Here is a Bubble sort program in C with a full explanation.
OutPut Of above Code:-
Explanation of above code:-
in bubble sort we know two adjacent numbers are to be compared if they are in an incorrect place then we have to swap it. so for this, we have to use one for loop and one another for loop for the number of variables because each variable is to be compared with others
Question:- Bubble sort program in C
Source Code:-
#include <stdio.h> int main() { int array[100], n, c, d, swap; printf("Enter number of elements\n"); scanf("%d", &n); printf("Enter %d integers\n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); for (c = 0 ; c < n - 1; c++) { for (d = 0 ; d < n - c - 1; d++) { if (array[d] > array[d+1]) { swap = array[d]; array[d] = array[d+1]; array[d+1] = swap; } } } printf("Sorted list in ascending order:\n"); for (c = 0; c < n; c++) printf("%d\n", array[c]); return 0; }
OutPut Of above Code:-
Explanation of above code:-
in bubble sort we know two adjacent numbers are to be compared if they are in an incorrect place then we have to swap it. so for this, we have to use one for loop and one another for loop for the number of variables because each variable is to be compared with others
Thanks You..@author sujeet kumar singh.Do you want to become a good programmer, Click Here
✽Send Solution and Get Credit✽
Must Read:-
4. Java Programming
5. C programs With source code
Final Word:-
In this article, We have shown you about the "Bubble sort program in C ".We hope you like it
5. C programs With source code
Final Word:-
In this article, We have shown you about the "Bubble sort program in C ".We hope you like it
If This post helps you a little bit then please share this post with your friends. For more Computer and programming Related Tips and tricks, please
Don't forget to share how you like this Content in the comment below. If you have any doubt or suggestion then please write in the comment section below, we will love to hear from you.
No comments:
Do not add any link in the comments.
For backlink, contact us.