Sorting Program1

#include<stdio.h>

#include<conio.h>


void main()

{

int i, j, limit, temp, no[97];

clrscr();


printf("How many numbers you want to enter? ");

scanf("%d", &limit);


printf("\nEnter %d numbers one by one\n", limit);

for(i=0; i<limit; i++)

{

printf("Enter number %d: ", i+1);

scanf("%d", &no[i]);

}


for(i=0; i<limit-1; i++)

{

for(j=0; j<limit-1; j++)

{

if(no[j] > no[j+1])

{

temp = no[j];

no[j] = no[j+1];

no[j+1] = temp;

}

}

}


printf("\n\nSorted Elements are as follow\n");

for(i=0; i<limit; i++)

{

printf("%d ", no[i]);

}

getch();

}


/*


Output:


How many numbers you want to enter? 10


Enter 10 numbers one by one

Enter number 1: 23

Enter number 2: 4

Enter number 3: 56

Enter number 4: 7

Enter number 5: 89

Enter number 6: 9

Enter number 7: 65

Enter number 8: 36

Enter number 9: 22

Enter number 10: 1



Sorted Elements are as follow

1 4 7 9 22 23 36 56 65 89


*/

No comments:

Post a Comment