/*Program to find the first and second largest number in the given array*/
#include<stdio.h>
void main()
{
int a[100];
int n,f=0,s=0,i;
printf("enter the number of elements in the array\n");
scanf("%d",&n);
printf(" \n enter the elements and press enter\n");
for(i=0;(i<n);i++)
{
scanf("%d",&a[i]);
if(a[i]>f)
{
s=f;
f=a[i];
}
if((a[i]>s)&&(a[i]<f))
s=a[i];
}
printf("%d is the first largest number \n",f); printf("%d is the second largest number \n",s);
}
No comments:
Post a Comment