I'm trying to assign user input using a two-dimensional array that takes five numbers and squares them. The program should calculate and store the squared values for each user in the array.
I'm getting the right output with the current code but I can't figure out how to assign the input to the array, without getting errors in the output.
#include <stdio.h>
int main(void)
{
int disp[2][5];
int x, y;
printf("Please enter 5 integer values:\n");
for(x=0; x<=2; x++) {
for (y=0; y<=5; y++) {
scanf("%d", &x);
printf("[ %d ][ %d ]\n", x, x*x);
}
}
return 0;
}
xas a loop variable, and as the input variable. That's bad. Also, when an array has 5 elements, the indexes into the array are 0,1,2,3,4. So theforloop should befor(y=0;y<5;y++).disp[x][y] = read_variable;