recent

C Program To Find Largest Element in Array

C Program To Find Largest Element in Array

#include<stdio.h>

int main()
{

   int a[30], i, num, largest;

   printf("Enter no of elements :\n");
   scanf("%d", &num);  //input from user

   for (i = 0; i < num; i++)
    {
     scanf("%d", &a[i]);  //elements entry in array
    }

   largest = a[0];

   for (i = 0; i < num; i++)
   {
      if (a[i] > largest)
 {
         largest = a[i];   //do sorting in asending order and first element of array is largest
      }
   }

   printf("largest Element : %d\n", largest);   //Print Output On screen

}
Powered by Blogger.