jituTechnology

jituTechnology

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…

No comments yet.

Add a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Connect with Me

GPO 8973 NPC 541; Kathmandu Nepal
Phone: +977 9851236800

Calendar

October 2019
S M T W T F S
« Jun    
 12345
6789101112
13141516171819
20212223242526
2728293031