الأحد، 25 يناير 2015

C++ Program : Ascending order array using bubble sort

This program takes 10 integers as an input , put them in an array and apply bubble sort algorithm .

The final result will be an array of 10 elements arranged in ascending order.

Sample:
a sample run of the program


The code: 

#include <iostream>

using namespace std;

void main()
{
int Num[10],index;
cout << " Enter five integers: ";
for (int i = 0; i < 10; i++)
{
cin >> Num[i];
}



cout << "The origional order is: " << endl;
for (int i = 0; i<10; i++)
{
cout << Num[i];
cout << endl;
}


for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (Num[j] >  Num[j + 1])
{
index = Num[j];
Num[j] = Num[j + 1];
Num[j+1] = index;
}

}
}

cout << endl;
cout << endl;
cout << "Ascending ordered Array is: " << endl;
for (int i = 0; i<10; i++)
{
cout << Num[i] << endl;
}



system("pause");
}

ليست هناك تعليقات:

إرسال تعليق