my second function does not seem to work. It is supposed to multiply each row of a 2D array by a 1D array. Im reading in a 2D and a 1D array from a file using I/O redirection <data1.txt > out1.txt. Can somebody point out the problem im doing. It does not print numbers.
Code:#include<stdio.h> #define SIZE 100 void calcSumAs(double a[][SIZE], double y[], int m, int n); void calcSumAXs(double a[][SIZE], double y[], double rs[], int m, int n); int main(void) { int m; int n; int i; int j; double ar[SIZE]; double prod[SIZE]; double mx[SIZE][SIZE]; double sum[SIZE]; double Y; scanf("%d%d", &m, &n); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) scanf("%lf", &mx[i][j]); } for (i = 0; i < m; i++) scanf("%lf", &ar[i]); calcSumAs(mx, sum, m, n); calcSumAXs(mx, ar, prod, m, n); for (i = 0; i < m; i++) printf("%lf ", prod[i]); return 0; } void calcSumAs(double a[][SIZE], double y[], int m, int n) { int i, j; for (i = 0; i < m; i++) for (y[i] = 0, j = 0; j < n; j++) y[i] += a[i][j]; return; } void calcSumAXs(double a[][SIZE], double y[], double rs[], int m, int n) { int i, j; for(i = 0; i < m; i++) for(rs[i] = 0, j = 0; j < n; j++) rs[i] += a[i][j] * y[j]; return; }



LinkBack URL
About LinkBacks


