- 1
can someone edit my code become like what i want?
so in my code now when input= 3 3 4 5 3 4 5 3 4 5 output= 3 4 5 3 4 5 3 4 5 but i want to make the output= 9 12 15 (9 from 3+3+3) (12 from 4+4+4) (15 from 5+5+5) https://code.sololearn.com/cjAs33hDXV0I/?ref=app
1 Odpowiedź
+ 3
I am not that good at c but this works for your example:
#include<stdio.h>
int main () {
int n;
scanf ("%d", &n);
int t[n][n];
int z[n];
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
scanf ("%d", &t[i][j]);
}
}
for (int j=0; j<n; j++) {
z[j] = 0;
for (int i=0; i<n; i++) {
z[j] += t[i][j];
}
printf ("%d ", z[j]);
}
printf ("\n");
}