Programming Examples
Write a program to print the five entered numbers in the ascending order
Write a program to print the five entered numbers in the ascending order.
Solution
#include<stdio.h>
void main()
{
int a,b,c,d,e,sum=0,i;
clrscr();
printf(“\nEnter Five numbers :”);
scanf(“%d %d %d %d %d”,&a,&b,&c,&d,&e);
printf(“\n Numbers in ascending order :”);
sum=a+b+c+d+e;
for(i=1; i<=sum;i++)
{
if(i==a || i==b || i==c || i==d || i==e)
{
printf(“%3d”,i);
}
}
}
Output
OUTPUT:
Enter Five numbers : 5 8 7 4 1
Numbers in ascending order : 1 4 5 7 8