Note. This is a homework question.
Use FOR construction to fill the 2D board with the values ββthat the user specified. The program asks for the board size n, m, and then asks for each board value.
My attempt
#include <stdio.h> int main(){ printf("Enter the number of columns"); int i = scanf("%d",&i); printf("Enter the number of rows"); int y = scanf("%d",&y); int r[i][y]; int a; int b; for (a=0; a<i; a++){ for(b=0; b<y; b++){ int r[a][b] = scanf("%d",&a,&b); //bug } } }
Bug: c:13 variable-sized object may not be initialized
EDIT:
#include <stdio.h> int main(){ printf("Enter the number of columns"); int i; scanf("%d", &i); printf("Enter the number of rows"); int y; scanf("%d", &y); int r[i][y]; int a; int b; for (a=0; a<i; a++){ for (b=0; b<y; b++){ scanf("%d",&r[a][b]); } } }
source share