0

Find a sum of 2D array, array must be generated by F. rand. why this code doesn't work ?

#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { srand(time(NULL)); int A[4][3], B[4][3], C[4][3]; int num; for(int i=0; i < 4; i++){ for(int j=0; j<3; j++) num = rand() % (100 - 1 + 1); A[i][j] = num; A[i][j] = num; } for(int i=0; i < 4; i++){ for(int j=0; j<3; j++) printf("%d\t", A[i][j]); } for(int i=0; i < 4; i++){ for(int j=0; j<3; j++) printf("%d\t", B[i][j]); } //compute C[4][3] for(int i=0; i < num; i++){ for(int j=0; j<num; j++) C[i][j] = A[i][j] + B[i][j]; } printf("C is \n"); for(int i=0; i < 4; i++){ for(int j=0; j<3; j++) printf("%d\t", C[i][j]); } return 0; }

13th Apr 2021, 10:50 AM
gedeon mubenga
gedeon mubenga - avatar
2 odpowiedzi
+ 4
Each for loop with „ j “ do no have the {} brackets.
13th Apr 2021, 10:58 AM
JaScript
JaScript - avatar
+ 2
You are filling array <A> twice in the first nested loop. There are more so I just edit the code. Edited code: https://code.sololearn.com/ccT1l3OB1lHO/?ref=app
13th Apr 2021, 10:54 AM
Ipang