Bubble Sort in c
On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
code in C:#include<stdio.h> int main() { int array[100], n, i, j, temp; printf("Enter number of elements\n"); scanf("%d", &n); printf("Enter %d integers\n", n); for (i = 0; i < n; i++) scanf("%d", &array[i]); for (i = 0 ; i < ( n - 1 ); i++) for (j = 0 ; j < n - i - 1; j++) if (array[j] > array[j+1]) /* For decreasing order use < */ { temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } printf("Sorted list in ascending order:\n"); for ( i = 0 ; i < n ; i++ ) printf("%d\n", array[i]); return 0; }output:-
Enter number of elements 5 Enter 5 integers 29 21 64 20 56 Sorted list in ascending order: 20 21 29 56 64 --------------------------------
0 comments: