Easy C program to sort 10 numbers in ascending order

sort 10 numbers in ascending order
Below we have given program by which user can sort 10 number in ascending order, this Sorting technique is also called as Bubble Sorting.

You can easily understand the working from image below given
sort 10 numbers in ascending order
Image Credits: codingeek.com

Program:


//a program to sort given 10 numbers in ascending order by SlashMyCode.com
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,a[10];
clrscr();
printf("Enter 10 integer numbers: \n");
     for(i=0;i<10;i++) //for loop to accept 10 numbers
        {
        scanf("%d",&a[i]);
        }


//sorting the numbers
    for (i=0;i<10;i++)
        {
        for(j=i+1;j<10;j++) /*j=i+1 since we want to compare first number with next number.*/
           {
             if(a[i]>a[j]) /*if loop to swap the numbers if first number is greater than second, we use 3rd variable (temp) for swapping */ 
               {
               temp=a[j];
               a[j]=a[i];
               a[i]=temp;
               }
           }
         }
printf("\n\nThe 10 numbers sorted in ascending order are: \n");
for(i=0;i<10;i++) // To print sorted numbers
{
printf("%d  ",a[i]);
}

//a program to sort given 10 numbers in ascending order by SlashMyCode.com
getch();
}


Output:
output of program to sort 10 numbers in ascending order

Flowchart:
flowchart of program to sort 10 numbers in ascending order
Click on image to enlarge.



Sharing is awesome 😉😉

No comments:

Post a Comment

Feel free to ask us any question regarding this post