Write C program to sort the given numbers in ascending orders.

Ascending order:

Ascending order means the elements will be sorted in increasing order.

Source Code:

#include <stdio.h> void main() { int num[5],i,j,temp; printf("Enter 5 numbers:\n"); for(i=0;i<5;i++) { scanf("%d",&num[i]); } for(i=0;i<5;i++) { for(j=i+1;j<5;j++) { if(num[i] > num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf("soted elements are:\n"); for(i=0;i<5;i++) { printf("%d ",num[i]); } }

Output:

Enter 5 numbers: 34 67 45 87 90 soted elements are: 34 45 67 87 90

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.