#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n, i, array[50], j, temp;
printf("Enter total number of elements :");
scanf("%d",&n);
printf("Enter %d numbers :",n);
for(i=0; i<n; i++)
{
scanf("%d",&array[i]);
}
printf("Sorting array using bubble sort technique...\n");
for(i=0; i<(n-1); i++)
{
for(j=0; j<(n-i-1); j++)
{
if(array[j]>array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
printf("Elements sorted successfully..!!\n");
printf("Sorted list in ascending order :\n");
for(i=0; i<n; i++)
{
printf("%d ",array[i]);
}
getch();
}
Run:
Previous Next
#include<conio.h>
void main()
{
clrscr();
int n, i, array[50], j, temp;
printf("Enter total number of elements :");
scanf("%d",&n);
printf("Enter %d numbers :",n);
for(i=0; i<n; i++)
{
scanf("%d",&array[i]);
}
printf("Sorting array using bubble sort technique...\n");
for(i=0; i<(n-1); i++)
{
for(j=0; j<(n-i-1); j++)
{
if(array[j]>array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
printf("Elements sorted successfully..!!\n");
printf("Sorted list in ascending order :\n");
for(i=0; i<n; i++)
{
printf("%d ",array[i]);
}
getch();
}
Run:
Previous Next
No comments:
Post a Comment