#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,j,t; //Take Array of 5 integers
clrscr();
printf("Enter 5 nos.\n\n");
for (i=0;i<5;i++) //Loop to fill array with five numbers
scanf("%d",&a[i]);
for (i=0;i<5;i++)
{
for(j=i+1;j<5;j++) //loop to compare which number is smaller
{
if(a[i]>a[j])
{
t=a[i]; // Swap small to large numbers
a[i]=a[j];
a[j]=t;
}
}
}
printf("Ascending Order is:"); //Print Result
for(j=0;j<5;j++)
printf("\n%d",a[j]);
getch();
}
******Description*******
1. If you wish to process multiple data inputs, use Array (Array is simply a sequence of memory location includes same type of data). Array can be made for int, char, float, etc. But mix form of array is not allowed. Like some array having elements both int and char is not allowed.
2. To put elements in array one should use 'Loop'. And very popular loop is 'FOR' loop. (Syntax of 'FOR' loop is 'for(initialization;condition;increment/decrement) )
3. Iteratively we compare each element with its successor. If we find it small then we will swap them.
4. We will loop this until end of array encounters
5. Now we have result.
6. To print the result we again will need loop.(Remember, to read or write to/from array you will need a loop)
7. And thats it. Post a comment for your queries.