Search
  • Soumen(ADMIN)

Bubble Sort in C

Updated: Aug 26



//bubble sort


#include<stdio.h>

#include<conio.h>


int main() {

int n,i,j,temp;

int arr[n];

printf("please enter how many number do you want to put?");

scanf("%d",&n);

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

printf("\nenter %d position number : ",i+1);

scanf("%d",&arr[i]);

}

printf("given array is : ");

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

printf("%d\t",arr[i]);


}

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

for(j=0; j<n-i-1; j++) {

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

temp = arr[j+1];

arr[j+1]=arr[j];

arr[j]=temp;

}

}

printf("list after sorting : ");

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

printf("%d\t",arr[i]);


}

}


OUTPUT

please enter how many number do you want to put?4


enter 1 position number : 12


enter 2 position number : 54


enter 3 position number : 36


enter 4 position number : 48

given array is : 12 54 36 48 list after sorting : -1 -1 -1 12

--------------------------------

Process exited after 61.11 seconds with return value 4

Press any key to continue . . .

14 views

Recent Posts

See All

Bisection Method in C

#include<stdio.h> #include<stdlib.h> #include<math.h> #define f(x) (x*x*x - x - 1) int main() { float x0,a,b; int k; float e = .001; do{ printf("please enter the value of a and b : "); scanf("%f%f",&a

Matrix Input using Array in C

#include<stdio.h> int main() { int a[20][20]; int i, j, m, n; printf("please enter the row and column number: "); scanf("%d %d",&m,&n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("\n Please enter a(

Addition Of Two Numbers in C

#include<stdio.h> #include<conio.h> void main() { int a; int b; int c; printf("Please enter the first Number: "); scanf("%d",&a); printf("Please enter the second Number: "); scanf("%d",&b); c=a+b; pri

  • Facebook Social Icon

©2019 by WEBTONEXT