A simple bubble sort program that I wrote using C programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website, kindly contact me also at my email address also. Thank you.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360.
Program Listing
bubble_sort.c
/* bubble_sort.c
Author : Mr. Jake Rodriguez Pomperada,BSCS,MAED-IT
Tool : Dev C++ 5.11
Date : April 18, 2019 Thursday 7:59 AM
Website : www.jakerpomperada.com and www.jakerpomperada.blogspot.com
Email : jake_pomperada@tup.edu.ph and jakerpomperada@gmail.com
Location : Bacolod City, Negros Occidental
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int items[1000], num=0, a=0, b=0, change=0;
system("cls");
printf("\n\n");
printf("\tBubble Sort Program in C");
printf("\n\n");
printf("\tHow many items? : ");
scanf("%d", &num);
printf("\n\n");
for (a= 0; a < num; a++) {
printf("\tEnter item no. %d: ", a+1);
scanf("%d", &items[a]);
}
printf("\n\n");
printf("\tOriginal Arrangement of Numbers");
printf("\n\n");
for ( a = 0 ; a < num ; a++ ) {
printf("\t%d ", items[a]);
}
for (a = 0 ; a < ( num - 1 ); a++)
{
for (b = 0 ; b < num - a - 1; b++)
{
if (items[b] > items[b+1])
{
change= items[b];
items[b]= items[b+1];
items[b+1] = change;
}
}
}
printf("\n\n");
printf("\tAsceding Order of Numbers");
printf("\n\n");
for ( a = 0 ; a < num ; a++ ) {
printf("\t%d ", items[a]);
}
printf("\n\n");
printf("\tEnd of Program");
printf("\n\n");
system("pause");
}
No comments:
Post a Comment