IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CMulti-Dimensional Arrays : Vector Multiplication
<09.03>
/* Multiplication of a matrix by a vector */
#include <stdio.h> #define COLS 3 #define ROWS 4 int main (void) { int i,k; int vec[3]={1,2,2}; int mat[4][3]={{1,1,1},{2,3,1},{1,-1,-1},{0,1,2}}; int prod[4]; /* do the multiplication */ for (i=0; i<ROWS; ++i) { prod[i] = 0; for (k=0; k<COLS; ++k) prod[i] = prod[i] + mat[i][k] * vec[k]; } /* display product vector */ printf ("The product is: <"); for (i=0; i<ROWS; ++i) printf ("%d, ", prod[i]); printf (">\n"); return (0); }
Hergestellt in Deutschland / Made in Germany
The product is: <5, 10, -3, 6, >
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland