C Program to Find The Largest Number in an Array

This program makes the concept of array more clear. As arrays are continuous memory locations, we can access them easily by incrementing the number (variable) in square bracket.

This method is used in this program.

Here using loop each and every element is comparing it with the other elements.


//program
#include <stdio .h>
 
int main()
{
int array[50], size, i, largest;
printf("\n Enter the size of the array: ");
scanf("%d", &size);
printf("\n Enter %d elements of  the array: ", size);
for (i = 0; i < size; i++)
scanf("%d", &array[i]);
largest = array[0];
for (i = 1; i < size; i++)
{
if (largest < array[i])
largest = array[i];
}
printf("\n largest element present in the given array is : %d", largest);
return 0;
}

Comments

Popular posts from this blog

Algorithm to display "n" natural numbers #c

Algorithm to display the sum of n natural numbers #c

Algorithm for Sum of two numbers