-->

Facebook

Jasper Roberts - Blog

Thursday, April 2, 2015

Write a C Program to given no in ascending order.

Practical Set - 4
5. Write a prograto given no in ascending order.

#include<stdio.h>
#include<conio.h>

void main()
{
    int i, j, temp, n, number[30];
    clrscr();
    printf("\n How Many Numbers: \n");
    scanf("%d", &n);
    printf("Enter the numbers: \n");
    for (i = 0; i < n; ++i)
        scanf("%d", &number[i]);
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (number[i] > number[j])
            {
                temp =  number[i];
                number[i] = number[j];
                number[j] = temp;
            }
        }
    }
    printf("Ascending order: \n");
    for (i = 0; i < n; ++i)
printf("%d\n", number[i]);

    getch();

}
OUTPUT:
How Many Numbers: 3
Enter the numbers: 
30
20
10
Ascending order:
10
20
30

No comments:

Post a Comment