-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathp7.c
47 lines (34 loc) · 889 Bytes
/
p7.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdlib.h>
#include <stdio.h>
void roteste_dreapta(const int* a, int* b, int n) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int elem = a[i * n + j];
b[j * n + (n - i - 1)] = elem;
}
}
}
int main() {
FILE* fin = fopen("p7.in", "r");
int n;
fscanf(fin, "%d", &n);
int* a = (int*)malloc(sizeof(int) * n * n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
fscanf(fin, "%d", &a[i * n + j]);
}
}
fclose(fin);
int* b = (int*)malloc(sizeof(int) * n * n);
roteste_dreapta(a, b, n);
FILE* fout = fopen("p7.out", "w");
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
fprintf(fout, "%d ", b[i * n + j]);
}
fprintf(fout, "\n");
}
fclose(fout);
free(a);
free(b);
}