Thursday 23 January 2014

Filled Under:

/* WAP to arrange 5 given numbers in ascending order */

/* WAP to arrange 5 given numbers in ascending order */

#include<stdio.h>
#include<conio.h>
void main()
{
    int num[5],i,j,temp;

    printf("Enter 5 Numbers:");
    for(i=0;i<=4;i++)
    {
        scanf("%d",&num[i]);
    }

    for(i=0;i<=4;i++)
    {
        for(j=i+1;j<=4;j++)
        {
            if(num[i]>num[j])
            {
                temp=num[i];
                num[i]=num[j];
                num[j]=temp;
            }
        }
    }

    printf("Ascending order:");
    for(i=0;i<=4;i++)
    {
        printf("\n%d",num[i]);
    }

    getch();
}

0 comments:

Post a Comment