Blogger templates

Pages

Wednesday, 18 July 2012

WAP to Find the Largest and Second Largest Number out of 10 Array Elements

Largest and Second Largest Number

Statement of C Program: This Program Prints the Largest and Second Largest Number out of 10 Array Elements:

#include<stdio.h>
#include<conio.h>
void main()
{
int A[10];
int i , j , b;
clrscr();

for(i=0 ; i<10 ; i++)
{
printf(" Enter the Number %d :" , i+1 );
scanf("%d" , &A[i] );
}

for(i=0 ; i<10 ; i++)
{
for(j=i ; j<10 ; j++)
{
if(A[i] < A[j])
{
b = A[j] ;
A[j] = A[i] ;
A[i] = b ;
}
}
}

printf(" Largest Number is : %d\n" , A[0] );
printf(" Second Largest Number is : %d\n" , A[1] );
getch();
}                                                     /* End of main() */

Output:
Enter the Number 1 : 90
Enter the Number 2 : 80
Enter the Number 3 : 70
Enter the Number 4 : 60
Enter the Number 5 : 50
Enter the Number 6 : 40
Enter the Number 7 : 30
Enter the Number 8 : 20
Enter the Number 9 : 10
Enter the Number 10 : 110

Largest Number is : 110
Second Largest Number is : 90

                                                                     That's All

0 comments:

Post a Comment