Лабораторная работа №7

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <math.h> #include <iomanip> using namespace std; const unsigned int D = 5; //const unsigned int DIM2 = 5; int ary[D][D]; void task907() { cout << "Задание №907\n"; int i; int j; int s[D]; for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { ary[i][j] = rand() % 10 ; cout << setw(5) << ary[i][j]; } cout << endl; } for(i=1; i < D; i++) { s[i]=0; for(j = 1; j<D-i+1; j++){ s[i] = s[i] + ary[j+i][j]; } cout << "Сумма диагонали под № " << i << " = " << s[i] << endl; } } void task942() { cout << "\nЗадание №942\n"; int i; int j; cout << "Начальная матрица:" << endl; for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { ary[i][j] = rand() % 10 ; cout << setw(5) << ary[i][j]; } cout << endl; } cout << "\n"<< endl; cout << "Конечная матрица:" << endl; for(i = 1; i<= D; i++){ ary[i][D-i+1] = 100; } for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { cout << setw(5) << ary[i][j]; } cout << endl; } } void task977() { cout << "\nЗадание №977\n"; int i; int j; int n; int k; n = 1; for (k=1; k < D; k++) { for (i = k; i < D-k+2; i++) { ary[k][i] = n; n++;} for (j = k+1; j < D-k+2; j++) { ary[j][D-k+1] = n; n++;} for (i = D-k; i > k-1; i--) { ary[D-k+1][i] = n; n++;} for (j = D-k; j > k; j--) { ary[j][k] = n; n++;} } for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { cout << setw(5) << ary[i][j]; } cout << endl; } } void task1012() { cout << "\nЗадание №1012\n"; int i; int j; int k; int n; int s; for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { ary[i][j] = rand() % 10 ; } } k=7;//столбец n=5;//строка for (i = 1; i <= D; i++) {ary[i][n] = i;} for (j = 1; j <= D; j++) {ary[k][j] = j;} ary[k][n] = 0; if(k < n) {ary[n][k+(n-k)] = 0; ary[n-(n-k)][k] = 0;} if(k > n) {ary[n+(k-n)][k] = 0; ary[n][k-(k-n)] = 0;} cout << endl; for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { cout << setw(5) << ary[i][j]; } cout << endl; } s = 0; for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { n=0; for (k = 1; k <= D; k++) { if(ary[i][k] == ary[k][j]) n++; } if(D == n) {cout <<"Cтрока " << i << " совпадает со столбцом " << j << endl; s++;} } } if(s == 0) {cout << "Совпадений не обнаружено " << endl;} } void task1047() { cout << "\nЗадание №1047\n"; cout << "\nИсходная матрица\n"; int i; int j; int b[D]; cout << endl; for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { ary[i][j] = rand() % 10 ; cout << setw(5) << ary[i][j]; } cout << endl; } cout << endl; cout << "\nЗадание а)"<< endl; for (i = 1; i <= D; i++){ b[i] = ary[i][1]; ary[i][1] = ary[i][5]; ary[i][5] = b[i]; } for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { cout << setw(5) << ary[i][j]; } cout << endl; } cout << "\nЗадание б)"<< endl; for (j = 1; j <= D; j++){ b[j] = ary[2][j]; ary[2][j] = ary[5][j]; ary[5][j] = b[j]; } for (i = 1; i <= D; i++) { for (j = 1; j <= D; j++) { cout << setw(5) << ary[i][j]; } cout << endl; } } int main() { task907(); task942(); task977(); task1012(); task1047(); }
Editor Settings
Theme
Key bindings
Full width
Lines