/* C Program To Find Second Largest Number In A Given Set Of Elements */
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int a[50],size,i,j=0,large,slarge;
printf("Enter the size of the array: ");
scanf("%d",&size);
printf("Enter the elements one by one:\n");
for(i=0;i<size;i++)
scanf("%d",&a[i]);
large=a[0];
for(i=1;i<size;i++){
if(large<a[i]){
large=a[i];
j = i;
}
}
slarge=a[size-j-1];
for(i=1;i<size;i++){
if(slarge <a[i] && j != i)
slarge =a[i];
}
printf("Second largest: %d", slarge);
return 0;
}
No comments:
Post a Comment