Write a program to sort data in ascending order using Bubble Sort.
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,j,k,l,n,temp=0;
clrscr();
printf("\t\tS O R T E D L I S T U S I N G B U B B L E S O R T");
printf("\nHow many enter value.");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
}
for(j=n-1;j>0;j--)
{
for(k=0;k<j;k++)
{
if(a[k]>a[k+1])
{
temp=a[k];
a[k]=a[k+1];
a[k+1]=temp;
}
}
}
printf("PASS");
for(l=0;l<n;l++)
{
printf("\n%d",a[l]);
}
getch();
}
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,j,k,l,n,temp=0;
clrscr();
printf("\t\tS O R T E D L I S T U S I N G B U B B L E S O R T");
printf("\nHow many enter value.");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
}
for(j=n-1;j>0;j--)
{
for(k=0;k<j;k++)
{
if(a[k]>a[k+1])
{
temp=a[k];
a[k]=a[k+1];
a[k+1]=temp;
}
}
}
printf("PASS");
for(l=0;l<n;l++)
{
printf("\n%d",a[l]);
}
getch();
}
Comments
Post a Comment