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

Popular posts from this blog

Suppose you are given a square matrix of size n x n, write a program to determine if this is an identity matrix. 2D array

Program to create a multiplication table of a given number using while loop.

Program to find equal values using if statement in C++