Bubble sorting of array in C++
Using Visual Studio 2015
===============================================================
#include<iostream>#include<conio.h>
using namespace std;
void main()
{
int array[5],temp;
for (int i = 0; i<5; i++)
{
cout << "Enter the number=";
cin >> array[i];
}
cout << endl;
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (array[j]>array[j + 1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
cout << "Bubble Sorted Array is " << endl;
for (int i = 0; i<5; i++)
{
cout << array[i] << endl;
}
_getche();
}
=========================================================================
Comments
Post a Comment