Hello, I seem to have an overflow that is giving me negative numbers instead of positive numbers. I tried using long long int arrays and it is an overflow. The program works for multiplying matrices when they are small numbers and low dimensions but not when I do a 100 x 150 matrix with numbers that are in the ten thousands.

Code:#include<stdio.h> #include"global.h" #include<string.h> void read_array(FILE *fp, FILE *fp2, long int array1[][NUM_COLUMN], long int array2[][NUM_COLUMN], int row1, int column1, int row2, int column2); void print_array(long int array3[][NUM_COLUMN], int row1, int column1, int row2, int column2); void multiply_array(long int array1[][NUM_COLUMN], long int array2[][NUM_COLUMN], long int array3[][NUM_COLUMN], int row1, int column1, int row2, int column2); int main(int argc, char **argv){ char txt[]=".txt"; long int ia[NUM_ROW][NUM_COLUMN]; long int ib[NUM_ROW][NUM_COLUMN]; long int ic[NUM_ROW][NUM_COLUMN]; FILE *fp; FILE *fp2; int col1,col2, rowa,rowb; /* checks for 3 arguments example [lab8 matrix_a.txt matrix_b.txt] */ if(argc!=3){ /*if(strstr(argv[1],txt)!=0){ printf("Usage: %s matrix_(letter).txt\n", argv[1]); }else{*/ printf("Usage: %s filename2.txt\n", argv[1]); return -1; //} } /* checks for .txt extension */ if((strstr(argv[1],txt)!=0) && (strstr(argv[2],txt)!=0)){ fp = fopen(argv[1], "r"); fp2 = fopen(argv[2], "r"); if((fp!=0)&&(fp!=0)){ fseek(fp, 0, SEEK_SET); fseek(fp2, 0, SEEK_SET); fscanf(fp, "%d %d", &rowa, &col1); fscanf(fp2, "%d %d", &rowb, &col2); read_array(fp, fp2, ia, ib, rowa, col1, rowb, col2); multiply_array(ia, ib, ic, rowa, col1, rowb, col2); if(col1==rowb) print_array(ic, rowa, col1,rowb, col2); fclose(fp); fclose(fp2); }else{ printf("%s and %s Not Open\n", argv[1], argv[2]); exit(-1); } } else printf("Unrecognized Arguments, files require *.txt extension"); return 0; }/* main()*/ void read_array(FILE *fp, FILE *fp2, long int array1[][NUM_COLUMN], long int array2[][NUM_COLUMN], int row1, int column1, int row2, int column2){ int i,j; //printf("row1 = %d\n", row1); //printf("row2 = %d\n", row2); //printf("column1 = %d\n", column1); //printf("column2 = %d\n", column2); for(i=0;i<row1;i++){ for(j=0;j<column1;j++) fscanf(fp,"%d", &array1[i][j]); fscanf(fp,"\n"); } for(i=0;i<row2;i++){ for(j=0;j<column2;j++) fscanf(fp2,"%d", &array2[i][j]); fscanf(fp2,"\n"); } } void print_array(long int array3[][NUM_COLUMN], int row1, int column1, int row2, int column2){ int i,j; for(i=0;i<row1;i++){ for(j=0;j<column2;j++) printf("%d ", array3[i][j]); printf("\n"); } } void multiply_array(long int array1[][NUM_COLUMN], long int array2[][NUM_COLUMN], long int array3[][NUM_COLUMN], int row1, int column1, int row2, int column2){ int i, j, k; long int sum; if(column1==row2){ for (i = 0; i < row1; i++) { for (j = 0; j < column2; j++) { sum = 0; for (k = 0; k < row2; k++) { sum += array1[i][k] * array2[k][j]; } array3[i][j] = sum; } } }else{ printf("Error in Matrix Multiplication\n"); printf("Cannot multiply when Column1 does not match with Row2 A[%d][%d] B[%d][%d]\n", row1, column1, row2, column2); } }

NUM_ROW and NUM_COLUMN defined in global.h as 250 for each.

Could anyone help? Thanks in advance.