A program to sort the data in ascending order using separate function to read, sort and display.
A program to sort the data in ascending order using separate function to read, sort and display.
Codes
/*A program to sort the data in ascending order using function*/
/*Programed by Jitendra Kr Yadav
10116
22 Mar,2011*/
#include<stdio.h>
#include<conio.h>
void read(int num[],int);
void sort(int num[],int);
void display(int num[],int);
main()
{
int n[20],x;
read(n,x);
sort(n,x);
display(n,x);
getch();
}
void read(int num[],int n)
{
int i;
printf(“Enter the number of data to input: “);
scanf(“%d”,&n);
printf(“Enter the data:\n”);
for(i=0;i<n;i++)
scanf(“%d”,&num[i]);
}
void sort(int num[], int n)
{
int i,j,temp;
for(i=0;i<=n-1;i++)
for(j=i+1;j<=n-1;j++)
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
void display(int num[],int n)
{
int i;
printf(“\n”);
printf(“The Ascending Order is\n”);
for(i=0;i<n;i++)
printf(“%d\t”,num[i]);
}
Output
Enter the number of data to input: 5
Enter the data:
5
6
4
2
1
The Ascending Order is
1 2 4 5 6
Press any key to continue…
Comments (1)