diff --git a/algorithms/C/README.md b/algorithms/C/README.md index 77a27dbe..da034e96 100644 --- a/algorithms/C/README.md +++ b/algorithms/C/README.md @@ -6,6 +6,7 @@ - [Unique Elements in an array](arrays/unique-elements-in-an-array.c) - [Reverse an array](arrays/reverse-array.c) - [Maximum difference](arrays/maximum-difference.c) +- [Largest Element](arrays/largestElement.c) ## Bit Manipulation diff --git a/algorithms/C/arrays/largestElement.c b/algorithms/C/arrays/largestElement.c new file mode 100644 index 00000000..dd3d6e9d --- /dev/null +++ b/algorithms/C/arrays/largestElement.c @@ -0,0 +1,62 @@ +/****************************************************************************** + Program to compute the largest element in array +******************************************************************************/ +#include +#define maxSize 100 + +int main() +{ + int array[maxSize], size; + int max; + + // Scanning the size of the array + printf("Enter the size of the array: "); + scanf("%d",&size); + + // Scanning the elements of array + printf("Enter the %d elements of the array: \n",size); + for(int i=0; i max) + { + max = array[i]; + } + } + + // Printing out the result + printf("\nThe largest element of the array: %d",max); + + return 0; +} + +/****************************************************************************** + OUTPUT SAMPLE +Enter the size of the array: 5 +Enter the 5 elements of the array: +Element [0]: 1 +Element [1]: 2 +Element [2]: 3 +Element [3]: 4 +Element [4]: 6 +The input array: +1 2 3 4 6 +The largest element of the array: 6 + +******************************************************************************/