1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include<stdio.h>
void read(int, int []);
void display(int, int []);
void sort(int, int []);
void main()
{
int num, data[50];
printf("Enter Total no of value to be sorted in Accessending Order:- ");
scanf("%d",&num);
read(num, data);
sort(num, data);
printf("After SUcessful Arangement in Accessending Order:- \n");
display(num,data);
}
void read(int x, int thedata[50])
{
int i;
printf("Enter the values to be inserted in the array:-\n");
for(i=0;i<x;i++)
{
scanf("%d",&thedata[i]);
}
}
void sort(int x, int thedata[50])
{
int i,j,tmp;
for(i=0;i<x-1;i++)
{
for (j=0;j<x-1;j++)
{
if(thedata[j]>thedata[j+1])
{
tmp=thedata[j];
thedata[j]=thedata[j+1];
thedata[j+1]=tmp;
}
}
}
}
void display(int x, int thedata[50])
{
int i;
for(i=0;i<x;i++)
{
printf("%d\t",thedata[i]);
}
}
|
Here we Use a function to read another to sort and another to display. As passing array is call by reference we need not to return individual value.
0 comments:
Post a Comment