Google Search

Sunday, October 30, 2011

WRITE A C PROGRAM TO FIND LARGEST AND SECOND LARGEST NUMBER OUT OF GIVEN NUMBER


WRITE A PROGRAM TO FIND LARGEST AND SECOND LARGEST NUMBER OUT OF GIVEN NUMBER

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[55],n,l=0,sl;
clrscr();
printf("How many no. will you enter: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
l=a[1];
for(i=0;i<n;i++)
{
if(a[i]>l)
{
l=a[i];
}
}
printf("Largest element is:%d",l);
sl=a[1];
for(i=0;i<n;i++)
{
if(a[i]>sl)
{
sl=a[i];
}
}
printf("Second Largest element is:%d",sl);
getch();
}




OUTPUT:
How many no. will you enter:
10
 Enter numbers
20
41
15
70
90
35
20
55
28
16
Largest element is: 90
Second Largest element is: 70

1 comments:

Post a Comment