#include <stdio.h>

#define MAXROW	40
#define MAXCOL	60

/* Dot-product of two vectors of length n */

double dotprod(double x[], double y[], int n)
{
	int i;
	double s = 0;

	for (i = 0; i < n; i++) s += x[i] * y[i];

	return s;
}

/*
 * matvec computes y = A x, where A is an m x n matrix and
 * x is a vector of length n
*/

void matvec(double A[][MAXCOL], double x[], double y[], int m, int n)
{
	int i, j;
	double s;

	for (i = 0; i < m; i++) {
		s = 0;
		for (j = 0; j < n; j++) s += A[i][j] * x[j];
		y[i] = s;
	}
}

int main()
{
	double A[MAXROW][MAXCOL];
	double x[MAXCOL], y[MAXROW];
	int m, n, i, j;
/*
 * 	Try a 2x3 matrix times a 3-vector
*/
	m = 2;
	n = 3;

	A[0][0] = 1.0;  A[0][1] = 2.0;  A[0][2] = 3.0;
	A[1][0] = 3.0;  A[1][1] = 4.0;  A[1][2] = 5.0;

	   x[0] = 5.0;     x[1] = 2.0;     x[2] = 4.0;
/*
 * 	Print the matrix and the vector x
*/
	printf("The matrix A is\n");
	for (i = 0; i < m; i++) {
		for (j = 0; j < n; j++) printf("%f ", A[i][j]);
       		printf("\n");
 	}

	printf("The vector x is\n");
	for (j = 0; j < n; j++) printf("%f ", x[j]);
	printf("\n");
/*
 * 	Compute and print the product y = A x
*/
	matvec(A, x, y, m, n);

	printf("The product y = A x is\n");
	for (i = 0; i < m; i++) printf("%f ", y[i]);
	printf("\n");

	return 0;
}


