0

Hello! I'm practising 2d-arrays for my upcoming test so pls help! i cant figure out what went wrong :(((((

Q: A factory has 3 divisions and stocks 4 products. An inventory data is updated for

each division and for each product as they are received. The current inventory data

is shown in Figure H10.1. The cost data of each product is given.

P1 P2 P3 P4

inventory for 1st division 10 13 14 23

inventory for 2nd division 21 24 18 5

inventory for 3rd division 9 14 12 4

Cost of each product

P1 35.45

P2 99.99

P3 210.50

P4 145.00

Write C program to calculate and display the inventory value of each

division.

This is what I wrote:

```
#include <stdio.h>
#define NO_OF_PROD 4
int main(void)
{
int row, col;
int stocks[3][NO_OF_PROD]={{10,13,14,23},{21,24,18,5},{9,14,12,4}};
double cost[4]={35.45,99.99,210.50,145.00};
double product[3];
void matrix_vector(int, int, int[][], double[], double[]);
matrix_vector(3,NO_OF_PROD,stocks,cost,product);
for (row=0;row<3;row++)
{ for (col=0;col<3;col++)
printf("Division inventory value=%lf\n", product[col]);
system("PAUSE");
return 0;
}
}
void matrix_vector(int row, int col, int stocks[][NO_OF_PROD], double cost[], double product[])
{
int i, j;
for(i=0;i<=row-1;i++)
product[i]=0.0;
for(j=0;j<=col-1;j++)
product[i]+=stocks[i][j]*cost[i];
}
```