2dix-The Student Choice
Log in Register now

C++ Program to find SECOND SMALLEST NUMBER IN AN UNSORTED ARRAY

Write a Program of SECOND SMALLEST NUMBER IN AN UNSORTED ARRAY

#include<iostream.h> 

#include<conio.h>

main()
{
int un[10], i, s1, s2;
clrscr();
printf("Enter array elements: ");
for ( i = 0; i < 10; ++i )
scanf("%d", &un[i]);
s1 = un[0];
for ( i = 1; i < 10; ++i )
{
if ( s1 > un[i] )

s1 = un[i];
if ( s1 != un[0] )
s2 = un[0];
else
s2 = un[1];
}
for ( i = 1; i < 10; ++i )
{
if ( s1 != un[i] && s2 > un[i] )
s2 = un[i];
}
printf("\nSecond smallest: %d", s2);
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.

comments (1)

avatar