Search

# Bubble Sorting in C

Random Post

#include<stdio.h>

void swap(int *m,int *n){

int temp=*m;

*m=*n;

*n=temp;

}

void bubbleSort(int arr[],int n){

int i,j;

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

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

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

swap(&arr[j], &arr[j+1]);

}

}

}

}

int main(){

int i,j,n,arr[n];

printf("Enter the number of elements: ");

scanf("%d",&n);

printf("\nEnter the elements:\n");

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

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

}

printf("The ascending order of elements using Bubble Sorting is:\n");

bubbleSort(arr,n);

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

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

}

return 0;

}

### Recent Posts

See All

#### Highest Divisor - CodeChef Solution | AskTheCode

CodeChef Feb Long Challenge Solution - Highest Divisor in C | Ask The Code...You are given an integer N. Find the largest integer...more

#### Enormous Input Test - CodeChef Solution in C | AskTheCode

CodeChef Practice Problem Solution in C Programming...Ask The Code...The purpose of this problem is to verify whether the method...Read more

#### C Program to find a number having max sum of divisors & also its position in the array

C Programming - AskTheCode | Write a C program display the number with maximum sum of divisors and its position in array...Ask The Code...