0
Subroutine work
Please, i need help with this. I don't know how to do this. The given matrix M(4,4). Find the product of the elements in each row of the matrix. Find the product of the elements in line in the form of a subroutine. Derive this matrix and the result.
7 odpowiedzi
+ 3
Call dob() inside the outer loop, but you'd need to adjust the output of the product.
This assumes the matrix has a static size of 4 (rows and columns). If matrix size varies, edit is in order.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
void dob(int[4]);
int main()
{
srand(time(NULL));
int A[4][4];
printf("Matrix:\n");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
A[i][j] = rand() % 100;
printf("%i\t", A[i][j]);
}
dob(A[i]);
printf("\n");
}
return 0;
}
void dob(int a[4])
{
int res = a[0] * a[1] * a[2] * a[3];
printf("Product: %d\n", res);
}
+ 4
Show your attempt.
+ 1
To get into all the matrix cases you should set a "for statement" inside an other "for statement".
Try to do it and we will see.
+ 1
What do you mean by "Derive this matrix and the result."?
+ 1
Ipang Print this matrix and result
0
Martin Taylor TheWitcher Michal Doruch
Im studying at university but im bad in C.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
void dob(int a, int b, int c, int d);
int main(){
srand ( time(NULL) );
int A[4][4];
printf("Matrix:\n");
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
A[i][j]=rand()%100;
printf("%i\t", A[i][j]);
}
printf("\n");
}
dob(A[0][1],A[0][2],A[0][3],A[0][4]);
return 0;
}
void dob(int a, int b, int c, int d){
int res = a*b*c*d;
printf("\nProduct:%d\n", res);
}