Info1-Uebungen/ub8/2Darr.c

47 lines
981 B
C
Raw Permalink Normal View History

2024-11-25 14:22:45 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *s = NULL;
size_t ss = 0;
do {
printf("enter \"Start\"! ");
getline(&s, &ss, stdin);
} while (strcmp(s, "Start") == 0);
free(s);
int a[2][8][8];
for (int m = 0; m < 2; m++) {
int c = 1 + m;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
a[m][i][j] = c;
c += (m == 0) ? 1 : 2;
}
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
char s1[8], s2[8], s3[8];
int ret = sprintf(s1, " %d", a[m][i][j]);
if (ret <= 0)
return -1;
ret = sprintf(s2, " %d", a[m][i][j]);
if (ret <= 0)
return -2;
ret = sprintf(s3, " %d", a[m][i][j]);
if (ret <= 0)
return -2;
printf("%s", a[m][i][j] > 9 ? a[m][i][j] > 99 ? s3 : s2 : s1);
}
printf("\n");
}
printf("\n\n");
}
return 0;
}