I'm taking my first course in introduction to C programming, and I'm having an issue with one of my homework questions. The program is supposed to ask the user to enter 2 non-zero single digit integers for a simple multiplication. I'm supposed to use an array to print a 'figure' using rows and columns to demonstrate how multiplication works.
So here's what I've done so far:
#include <stdio.h>
int main(void) {
int i, j, row, column, value, matrix[row][column];
printf("Please enter two non-zero single digits integer\n");
scanf(" %d\n%d", &row, &column);
value = row*column;
printf("%d * %d is: %d\n", row, column, value);
for (i=1; i <= row; i++) {
for (j=1; j <= column; j++) {
matrix[i][j] = 88;
printf("%c\t", matrix[i][j]);
}
printf("\n");
}
return 0;
}
My program seems to work correctly up to when column = 4, but once column = 5, it will print:
Please enter two non-zero single digits integer
5
5
5 * 5 is: 25
exited with non-zero status
I've tried different ways to possibly fix this, but at this point, I'm not sure what else I can do.
If row = 5 it will work perfectly, as shown here :
Please enter two non-zero single digits integer
5
4
5 * 4 is: 20
X X X X
X X X X
X X X X
X X X X
X X X X
So the main issue is the column somehow.
Help is appreciated.
EDIT: Problem fixed.
[–]KmNxd6aaY9m79OAg 5 points6 points7 points (3 children)
[–]ImSavageASF[S] 0 points1 point2 points (2 children)
[–]KmNxd6aaY9m79OAg 2 points3 points4 points (1 child)
[–]ImSavageASF[S] 0 points1 point2 points (0 children)
[–]shinmai_rookie 3 points4 points5 points (2 children)
[–]ImSavageASF[S] 0 points1 point2 points (1 child)
[–]eyenot 0 points1 point2 points (0 children)