Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <locale.h>
- #include <math.h>
- #include <stdio.h>
- #include <malloc.h>
- void PrintArray(int** a, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++)
- printf("%3d", a[i][j]);
- printf("\n");
- }
- }
- void DDD(int** a, int n) {
- int x = 1;
- for (int s = 0; s < n * n; s++) {
- if (s % 2 == 0) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if ((i + j) == s) {
- a[j][i] = x;
- x++;
- }
- }
- }
- }
- if (s % 2 == 1) {
- for (int j = 0; j < n; j++) {
- for (int i = 0; i < n; i++) {
- if ((i + j) == s) {
- a[j][i] = x;
- x++;
- }
- }
- }
- }
- }
- }
- void main()
- {
- setlocale(LC_ALL, "rus");
- int n;
- printf("Введите размер n квадратной матрицы: ");
- do {
- scanf_s("%d", &n);
- if (n <= 0)
- printf("Повторите ввод, введите положительное число: ");
- } while (n <= 0);
- int** a = (int**)malloc(sizeof(int*) * n);
- for (int i = 0; i < n; i++) {
- a[i] = (int*)malloc(sizeof(int) * n);
- }
- DDD(a, n);
- PrintArray(a, n);
- getchar(); getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement