A C Program
A C Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int n;
int i;
int j;
int temp;
printf("Enter the size of the array");
scanf("%d",&n);
printf("Enter the values in the array\n");
for(i=0;i<n-1;i++)
{
scanf("%d",&a[i]);
}
//Now, the sorting starts, with:
//a variable, called as j, which begins at 0, the start of the array
//and compares itself, or the value it contains with the next ie j+1 variable of
the list, as is the main principle of bubble sort
//and, if it is greater, it swaps the postions, with help of a temp variable. it
stores its value in temp and then stores j+1 in j
//and, finally it exchanges the old value of j , now in temp with j+1
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
printf("The sorted array is: \n");
for(i=0;i<=n-1;i++)
{
printf("%d\n",a[i]);
}
getch();
}