0

How can i sort this array pls..

#include<iostream>
#include<algorithm>
using namespace std;
int prompt(int x[]);
void printreverse(int x[]);


int main()
{
	int x[5];
	prompt(x);
	printreverse(x);
	
	system("pause");
	return 0;
}

int prompt(int x[])
{
	
	for(int i=0;i<5;i++)
	{
		cout <<"Enter integers:";
		cin >>x[i];
	}
}



void printreverse(int x[])
{
	for(int i=0;i<5;i++)
	{
		cout <<x[i]<<" ";
	}
	cout <<endl;
}
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by firstPerson
0

The most direct way, since you've already included the algorithm header, is to use std::sort().

0

Use the suggestion above, although you might want to google sorting for knowledge experience.

You can do this if you want to use std::sort;

#
int main()
{
int x[5];
prompt(x);
printreverse(x);
std::sort(x,x+5);
system("pause");
return 0;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.