Skip to main content

BubbleSort77

bubble sort
#include<stdio.h>
int main()
{
int i,j,n,a[100],temp;
printf("enter the number of elements");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;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("sorted arry\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
return 0;
}
Algorithm: BubbleSort
Start

read n

for i= 0 to n-1

read a[i]

for i=0 to n-1

for j=0 to n-i-1

if (a[j] > a[j+1])

temp = a[j]

a[j] = a[j+1]

a[j+1] = temp

for i=0 to n-1

print a[i]

Stop

Comments

Popular posts from this blog

Raju is a Civil Engineer. He is writing software to automate his work. As a part of his requirement, he wants to calculate the circle diameter, circumference, and area. Help Raju to complete his task. Get radius as input.

OUTPUT

Select the option that is most nearly OPPOSITE in meaning to the word or phrase is given in bold. Birds are quarantined to prevent the spread of bird flu.

Select the option that is most nearly OPPOSITE in meaning to the word or phrase is given in bold. Birds are  quarantined  to prevent the spread of bird flu. immunized butchered secluded CORRECT mingled