C program to sort array elements in ascending order


C program to sort array elements in ascending order



 /********************************************

 C program to sort array elements in ascending and descending order

 *******************************************/

#include<stdio.h>

#include<conio.h>

void main()

{

int arr[100];

int n,i,j,temp;

clrscr();

printf("How many array elements\n");

scanf("%d",&n);

printf("Enter array elements\n");

for(i=0;i<n;i++)

{

scanf("%d",&arr[i]);

}

printf("The sorting order of array elements is\n");

for(i=0;i<n;i++)

{

for(j=i+1;j<n;j++)

{

if(arr[i]>arr[j])

{

temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

}

}

printf("%d\t",arr[i]);

}

printf("\nEnd of program");

}


How many array elements

10

Enter array elements

1

6

2

9

10

4

8

7

3

2

The sorting order of array elements is

1 2 2 3 4 6 7 8 9 10

End of program


टिप्पणी पोस्ट करा

0 टिप्पण्या