Answer to Question #5376 in C++ for anum

Question #5376
q#3 write a program which takes 20 number from the user,sort those numbers in descending order. the array should be passed to sorting function.
1
Expert's answer
2011-12-01T08:34:32-0500
// SortArrayC++.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include "conio.h"

using namespace std;

void bubbleSort(int aray[],int length)//Bubble sort function
{
int i,j;
for(i=0;i<length;i++)
{
for(j=0;j<i;j++)
{
if(aray[i]>aray[j])
{
int temp=aray[i]; //swap

aray[i]=aray[j];
aray[j]=temp;
}

}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int n;
int array1[100];
cout<<"Enter the number of elements : ";
cin>>n;
for(int i=0;i<n;i++){
cout<<"Enter the "<<i+1<<" element : ";
cin>>array1[i];
}
bubbleSort(array1,n);
for(int i=0;i<n;i++){
cout<<array1[i]<<" ";
}
cout<<"
Press any key to exit....";
getch();

return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS