bubble

bubble


#include<stdio.h>


int main(){

int n,i,j;

int t,k,p;

int o;

int c;

printf("Enter no.of elements");

scanf("%d",&n);

int a[n];

for(k=0;k<n;k++){

scanf("%d",&a[k]);

}

for (i=0;i<n;i++){

printf("Iteration %d \n",i);

for (j=0;j<n;j++){

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

t=a[j];

a[j]=a[j+1];

a[j+1]=t;

c=1;

}

else{

c=0;

}

if(c==1){

printf("The swaped values are %d %d \n",a[i],a[j]);

for (o=0;o<n;o++){

printf("%d ",a[o]);

}

printf("\n");

}

else{

printf("No values swaped \n");

for (o=0;o<n;o++){

printf("%d ",a[o]);

}

printf("\n");

}

}

}

for(p=0;p<n;p++){

printf("%d ",a[p]);

}

}

Report Page