C++
Создайте двумерный массив типа int, произвольного размера, используя генератор случайных чисел. Выведите на экран все числа в порядке возрастания.
Ответы
Ответ дал:
0
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int n, i;
int main() {
vector <int> x;
cin >> n;
srand(time(0));
for (; i < n; ++i) {
x.emplace_back(rand());
}
for (i = 0; i < n; ++i) {
cout << x[i] << " ";
}
cout << endl;
sort(x.begin(), x.end());
for (i = 0; i < n; ++i) {
cout << x[i] << " ";
}
return 0;
}
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int n, i;
int main() {
vector <int> x;
cin >> n;
srand(time(0));
for (; i < n; ++i) {
x.emplace_back(rand());
}
for (i = 0; i < n; ++i) {
cout << x[i] << " ";
}
cout << endl;
sort(x.begin(), x.end());
for (i = 0; i < n; ++i) {
cout << x[i] << " ";
}
return 0;
}
Вас заинтересует
2 года назад
9 лет назад
9 лет назад