A program to sort the elements of an array using pointer and function.
A program to sort the elements of an array using pointer and function.
Codes
/*A program to sort the elements of an array using pointer and function*/
/*Programed by Jitendra Kr Yadav
10116
2Apr,2011*/
#include<stdio.h>
#include<conio.h>
void sort(int, int*);
main()
{
intn,i,a[20];
printf(“Enter the no of input to be taken:”);
scanf(“%d”,&n);
printf(“Enter the input:\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
sort(n,&a[0]);
printf(“Sort: “);
for(i=0;i<n;i++)
printf(“%d\t”,a[i]);
printf(“\n\n”);
printf(“Press any key to continue…”);
getch();
}
void sort(intx,int*num)
{
inti,j,temp;
for(i=0;i<=x-1;i++)
for(j=i+1;j<=x-1;j++)
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
Output
Enter the no of input to be taken: 5
Enter the number:
3
6
9
7
1
Sort: 1 3 6 7 9
Press any key to continue…