Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- void show_Ary(int **Ary, int num) {
- for (int i = 0; i < num; i++) {
- for (int j = 0; j < num; j++) {
- cout << setw(3) << Ary[i][j];
- }
- cout << endl;
- }
- }
- int* generate_first_Ary(int num) {
- int *tempAry = new int[num*num];
- for (int i = 0; i < (num)*(num); i++) {
- tempAry[i] = -(num)+rand() % (num - (-num) + 1); // формула для получения случайного числа от min до max
- cout << "Никита лох ";
- }
- return tempAry;
- }
- void sort_first_Ary(int *tempAry, int num) {
- bool ok = false;
- int temp;
- while (!ok) {
- ok = true;
- for (int k = 0; k < (num)*(num); k++) {
- if (tempAry[k] < tempAry[k + 1]) {
- temp = tempAry[k];
- tempAry[k] = tempAry[k + 1];
- tempAry[k + 1] = temp;
- ok = false;
- }
- }
- }
- }
- int** generate_second_Ary(int* tempAry, int num) {
- int **Ary = new int*[num];
- for (int i = 0; i < num; i++) {
- Ary[i] = new int[num];
- }
- int counter = 0;
- for (int i = 0; i < num; i++) {
- for (int j = 0; j < num; j++) {
- Ary[i][j] = 0;
- }
- }
- for (int i = 0; i < num; i++) {
- for (int j = 0; j < num; j++) {
- if (i % 2 == 0) {
- Ary[j][i] = tempAry[counter];
- }
- else {
- Ary[(num - 1) - j][i] = tempAry[counter];
- }
- counter++;
- }
- }
- return Ary;
- }
- int main() {
- setlocale(LC_ALL, "rus");
- srand(time(0));
- int N;
- cout << "Введите N ";
- cin >> N;
- int *tempAry = generate_first_Ary(N + 15);
- sort_first_Ary(tempAry, N + 15);
- int **Ary = generate_second_Ary(tempAry, N + 15);
- show_Ary(Ary, N + 15);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement