Saturday, 2 April 2016

Q. Find the two largest values among the 10 numbers. 
Note: You must input each number only once.

#include<stdio.h>
#include<conio.h>


void main()
{
int n,fl,sl,x;
fl=0;
sl=0;
for (x=1 ; x<=10 ; x++)
{
printf("Enter a number:");
scanf("%d",&n);
if((n>fl)&&(n>sl))
{
sl=fl;
fl=n;
}
else if(n>sl)
sl=n;
}
printf("1st largest %d\t",fl);
printf("2nd Largest %d",sl);
getch();
}

No comments:

Post a Comment