11:21 AM
C++ Program to find SECOND LARGEST NUMBER IN AN UNSORTED ARRAY

Write a Program to find SECOND LARGEST NUMBER IN AN UNSORTED ARRAY

#include<iostream.h> 

#include<conio.h>
 
main()
{
int un[10], i, big1, big2;
21
By:Ms-Kamalpreet Kaur (14960)
printf("Enter array elements: ");
for ( i = 0; i < 10; ++i )
scanf("%d", &un[i]);
big1 = un[0];
for ( i = 1; i < 10; ++i )
{
if ( big1 < un[i] )
big1 = un[i];
if ( big1 != un[0] )
big2 = un[0];
else
big2 = un[1];
}
for ( i = 1; i < 10; ++i )
{
if ( big1 != un[i] && big2 < un[i] )
big2 = un[i];
}
printf("Second largest: %d\n", big2);
return 0;
}
 
 
 
Note:
      If you want to change in this program please write through the comment on this page. you can also past similar program 
                 of c++ with output.your comment is valuable to the other user and person.
 
Views: 106 | Added by: vijoriya | Tags: UNSORTED, Number, Largest, array, c++, Second, program | Rating: 0.0/0
Total comments: 0
avatar