This repository has been archived on 2026-07-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
college-work/Задания по C и C++/c/10.c
T

39 lines
823 B
C
Executable File

/*
10.Создать целочисленный массив A[5][5]. При помощи цикла и оператора условия задать его значения, как показано ниже:
1 2 3 4 5
2 3 4 5 4
3 4 5 4 3
4 5 4 3 2
5 4 3 2 1
*/
#include <stdio.h>
#define N 5
void setArray(int (*array)[N]) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
array[i][j] = (i + j) < (N-1) ? i + j + 1 : (N*2 - 1) - (i+j);
}
}
}
void printArray(int (*array)[N] ) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
printf("%d ", array[i][j]);
}
puts("");
}
}
int main() {
int A[N][N];
setArray(A);
printArray(A);
return 0;
}