Bhuvan InfoTech Android App

Download our Android App and browse Technical News, Projects, Computer Tricks more easily with lots of Interesting Features.

Tuesday, June 14, 2016

Bubble sort | C program


#include <stdio.h>

void bubblesort(int arr[], int size)

{

int i, j;

for (i = 0; i < size; i++)

{

for (j = 0; j < size - i; j++)

{

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

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



}

}

}

void swap(int *a, int *b)

{

int temp;

temp = *a;

*a = *b;

*b = temp;

}

int main()

{

int array[100], i, size;

printf("How many numbers you want to sort: ");

scanf("%d", &size);

printf("\nEnter %d numbers : ", size);

for (i = 0; i < size; i++)

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

bubblesort(array, size);

printf("\nSorted array is ");



for (i = 0; i < size; i++)

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

return 0;

}
Bhuvan Arora

No comments:

Amazing Deal !