#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable : 4996)
void main() {
int matrix[30][50];
int sizeRow, sizeCol;
printf("Number of Rows in your table : ");
scanf("%d", &sizeRow);
printf("Number of Columns in your table : ");
scanf("%d", &sizeCol);
int sum[sizeRow] = { 0 };
for (int row = 0; row < sizeRow; row++){
for (int col = 0; col < sizeCol; col++){
printf("Input element [%d][%d] : ", row, col);
scanf("%d", &matrix[row][col]);
sum[row] += matrix[row][col];
}
}
printf("Total of each row:\n");
for (int row = 0; row < sizeRow; row++){
printf("ROW[%d] SUM :\t%d\n", row, sum[row]);
}
system("pause");
}
I get an error in int sum[sizeRow] = { 0 };where it says that my array should be constant, but the user in my case should determine the size of the array. How can i fix this?
source
share