Input five numbers in an array and write a program to sort them (Using Bubble 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 = 0; j < 5 - ( i + 1 ); j++ )
{
if ( nos[ j] >= nos[ j +1] )
{
tem = nos [ j];
nos[ j] = nos[ j + 1];
nos[ j + 1] = 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
#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 = 0; j < 5 - ( i + 1 ); j++ )
{
if ( nos[ j] >= nos[ j +1] )
{
tem = nos [ j];
nos[ j] = nos[ j + 1];
nos[ j + 1] = 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