Program to Sort(in ascending order) set of numbers using BUBBLE SORT
#include<stdio.h>
#include<conio.h>
#include<process.h>
#define true 1
#define false 0
int arr[10],n,i,j,temp;
void main()
{
clrscr();
printf("Enter size of array:");
scanf("%d", &n);
if(n>10)
{
printf("Entered value exceed the limit of array");
getch();
exit(0);
}
printf("\n Enter array elements....");
for(i=0;i<=n-1;i++)
scanf("%d",&arr[i]);
//LOGIC of BUBBLE SORT
for(i=0;i<n-1;i++)
{
for(j=0;j<(n-1)-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("\n Sorted Array....");
for(i=0;i<=n-1;i++)
printf("\n%d",arr[i]);
getch();
}
#include<conio.h>
#include<process.h>
#define true 1
#define false 0
int arr[10],n,i,j,temp;
void main()
{
clrscr();
printf("Enter size of array:");
scanf("%d", &n);
if(n>10)
{
printf("Entered value exceed the limit of array");
getch();
exit(0);
}
printf("\n Enter array elements....");
for(i=0;i<=n-1;i++)
scanf("%d",&arr[i]);
//LOGIC of BUBBLE SORT
for(i=0;i<n-1;i++)
{
for(j=0;j<(n-1)-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("\n Sorted Array....");
for(i=0;i<=n-1;i++)
printf("\n%d",arr[i]);
getch();
}
Comments
Post a Comment