WAP in C to Find Largest Element in an Array?

#include<stdio.h>
#include<conio.h>
int main()
{
int a[30],i,num,largest;
clrscr();
printf(“\nEnter size of array:”);
scanf(“%d”, &num);
//Read n elements in an array
printf(“\nEnter the elements of array:”);
for (i=0;i<num;i++)
scanf(“%d”, &a[i]);
//Consider first element as largest
largest = a[0];
for (i=0;i<num;i++)
{
if (a[i] > largest
{
largest = a[i];
}
}
// Print out the Result
printf(“\nLargest Element : %d”, largest);
getch();
return(0);
}

Output :-

lararr

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s