Right Click to Search

Tuesday, December 29, 2024

Find Largest Element in Array in C Programming


Program : Find Largest Element in Array in C Programming [Updated]
// ------------------------------------------
// Title : Find out Largest Number From Array
// Largsest - It Stores the Largest number
// ------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
  {
  int a[30],i,n,largest;
  printf("\n Enter no of elements :");
  scanf("%d",&n);
  /* read n elements in an array  */
  for(i=0 ; i < n ; i++)
     scanf("%d",&a[i]);
  largest = a[0];
  for(i = 0;i<n;i++)
  {
  if(a[i] > largest )
      largest = a[i];
  }
  /* Print out the Result */
     printf("\nLargest Element : %d",largest);
     getch();
}


Tags / Keywords : |

Stumble
Delicious
Technorati
Twitter
Facebook

1 Comment:

Victor said...

Please correct where:
if (a[i] < largest)
largest = a[i]
***************
Should be:
if (a[i] > largest )
largest = a[i]

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates