/* * program to build and print values in a 2D array, sort of: * * to keep things simple(?), build the array in a fixed-size 1D * array containing the rows of the 2D array one after another. */ #include int A[100]; int main(void) { int a, b; int i, j, k; printf("Enter integers for a and b, one per line:\n"); scanf("%d", &a); scanf("%d", &b); /* optional print */ printf("\nYou entered:\n"); printf("%d\n", a); printf("%d\n", b); /* size check */ if (a*b > 100) { printf("Array size exceeds maximum\n"); return 0; } /* put values in array */ for (i = 0; i < a; ++i) for (j = 0; j < b; ++j) A[b*i + j] = i + j; /* print results */ printf("\nResults:\n"); for (k = a*b-1; k >= 0; --k) { printf("%d\n", A[k]); } return 0; }