Pages

Monday 21 May 2012

a program to print sorted array


101./*Write a program to print sorted array*/

#include<stdio.h>
#include<conio.h>
main()
{
            int array[10],i,j;
            int temp;
            clrscr();

            printf("Enter ten number:\n");
            for(i=0;i<10;i++)
            {
                        scanf("%d",&array[i]);
            }
            for(i=0;i<5;i++)
            {
            for(j=0;j<10;j++)
            {
            if(array[j]>array[j+1])
            {
            temp=array[j];
            array[j]=array[j+1];
            array[j+1]=temp;
            }
            }
            }
            printf("The sorted array is:\n");
            for(i=0;i<10;i++)
            {
            printf("%d\n",array[i]);
            }
            getch();
}

OUTPUT
            Enter ten number :
            4
            8
            2
            3
            4
            6
            1
            6
            2
            4
            The sorted array is :
            1
            2         
            2
            3
            4
            4

No comments:

Post a Comment