In the output for the sorted integers they know display in one long column. I would like the 1:s on one row the 2:s on one row etc..
For example
How do I do that?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <vector>
#include <iomanip>
#include <ctime>
#include <random>
#include <algorithm>
using namespace std;
int main()
{
vector<int> randomIntegers;
int num;
default_random_engine generator(static_cast<int>(time(0)));
uniform_int_distribution<int> random(1, 100);
vector<int> randomIntegers2;
randomIntegers2 = randomIntegers;
cout << " How many integers do you want to randomize: " ;
cin >> num;
for(int i=0; i < num; i++)
randomIntegers.push_back(random(generator));
int cnt = 1;
for(auto e : randomIntegers)
{
cout << setw(5) << e;
if (cnt++ % 10 == 0)
cout << "\n";
}
sort(randomIntegers.begin(),randomIntegers.end());
cout << "\n" << "\n" << "Sorted vector" << "\n";
cnt = 1;
for(auto e : randomIntegers)
{
cout << setw(4) << e << endl;
}
}
|
Last edited on