/*write a c program to sort array element using bubble sort
method.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,temp=0;
clrscr();
printf("how many number you want to enter:-");
scanf("%d",&n);
printf("\nenter number for an array");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
n=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
n++;
printf("\nthe sorted array is:-\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}
/*how many number you want to enter:-4
enter number for an array5
8
7
1
the sorted array is:-
1
5
7
8
*/
No comments:
Post a Comment