Archived
Работы по программированию
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
9.Создать целочисленный массив A[5][5]. При помощи цикла и оператора условия задать его значения, как показано ниже:
|
||||
5 4 3 2 1
|
||||
4 3 2 1 2
|
||||
3 2 1 2 3
|
||||
2 1 2 3 4
|
||||
1 2 3 4 5
|
||||
*/
|
||||
|
||||
#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++) {
|
||||
int result;
|
||||
if ( i+j < N) {
|
||||
result = N - (i+j);
|
||||
} else {
|
||||
result = (i+j) - (N - 2);
|
||||
}
|
||||
array[i][j] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user