Input five numbers in an array and write a program to sort them (Using Selection sort method).
#include <stdio.h>
#include <conio.h>
void main ( )
{
int nos[5], i, j, tem;
clrscr ( );
for ( i = 0; i < 5; i++ )
{
printf ("\n\t\t\t Enter a number...........:"); scanf ("%d", &nos[i]);
}
for ( i = 0; i < 5; i++ )
{
for ( j = i + 1; j < 5; j++ )
{
if ( nos[i] >= nos[ j] )
{
tem = nos [i];
nos[i] = nos[ j];
nos[ j] = tem;
}
}
}
printf ("\n\n");
for ( i = 0; i < 5; i++ )
{
printf ("\n\t\t Position : %d \t Output Number : %d", i, nos[i] );
}
getch ( );
}
Click here to contact us
No comments:
Post a Comment