C++ Program of Sorting Elements of Array

ad+1

In this C++ program we will sort an unsorted array. First of all we will take input from user using for loop. And then we will sort that array using if condition in nested for loop.

Program:



// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com
 
#include<iostream>
using namespace std;

int main()
{
    int a[10], i=0 ,j=0, temp=0;
  

    for(i=0; i<10; i++)
    {
       cout<<"Enter " <<i <<" Element of Array: ";
        cin>>a[i];
     }

       
    for(i=1; i<10 ;i++)
    {
        for(j=0; j<(10-i); j++)
       
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
    }
   

    cout<<"Array after bubble sort is:";

    for(i=0 ;i<10; i++)
    {
     cout<<" "<<a[i];
    }
       
    return 0;

}  //end of main function

Output:

2 comments: Leave Your Comments

  1. If so, the best treatment is surgery, often with preop chemoradation. I would think this treatment would be available at any hospital.
    No doctor would give a prescription for anything without examining the patient, reviewing their records and getting a history and it certainly would not be a plant extract.

    solve your afp problems

    ReplyDelete


  2. nice information for the freshers.thank you.
    learn c++ tutorial

    ReplyDelete