C Program Sorting of Array

This is a simple program to sort a array. This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1


#include<conio.h>
#include<stdio.h>
void main()
{
int a[100],i,j,n,temp;
clrscr();
printf("\n Enter the number of elements to sort");
scanf("%d",&n);
printf("\n Enter the elements  in the array");

for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Array in sorted form is as follows ");
for(i=0;i<n;i++)
{
for(j=0;j<(n-1-i);j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
//a[j]=(a[j]>a[j+1])?a[j]:a[j+1];
}
}
}
for(i=0;i<n;i++)
{
printf("%d \t",a[i]);
}
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment