Alex is found of doing string programs. One day his professor gave him a string based question to solve in a linear time complexity. The program is to change a strit to its diagonal string inter the form of X ( I. e Diagonal from left right and from right left) help him finish it
Here is program:
int main() {
srand(time(0));
int a[n][n];
for (int r = 0; r < n; ++r) {
for (int c = 0; c < n; ++c) cout << setw(3) << (a[r][c] = rand() % 100);
cout << endl;
}
cout << "Main: ";
for (int c = 0; c < n; ++c) cout << setw(3) << a[c][c];
cout << "Side: ";
for (int c = 0; c < n; ++c) cout << setw(3) << a[c][n - 1 - c];
}
9
9
Нравится
Comments
Leave a comment