Question : Write a C program which includes a user defined
function. This program finds the sum of elements from every
column and product of elements from every row of a 5x5
randomly constructed matrix.
Your program should print the smallest sum including the index
of its column, and the biggest product including the index of its
row.
In the main function:
- Define and construct 5x5 matrix randomly.
- Pass this matrix to the user defined function
In the user defined function:
- Calculate the sum of elements from every column and
product of elements from every row of the matrix.
- Print the smallest sum including the index of its column,
and the biggest product including the index of its row.
Can you help how to do this homework? I can do it without pointers and functions but i cant do with those.
I started like this but i couldnt continue because i cannot even add the column with a function:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
int a[5][5],i,j;
int *b;
for(i=0;i<5;i++){
for (j=0;j<5;j++){
a[j]=rand()%100;
}}
for(i=0;i<5;i++){
for (j=0;j<5;j++){
printf("%d ",a[j]);
}
printf("\n");
}
int sum=0;
for(j=0;j<5;j++){
for (i=0;i<5;i++){
sum=sum+a[j];
}
printf(" sum=%d\n", sum);
sum=0; }
return 0;
}
function. This program finds the sum of elements from every
column and product of elements from every row of a 5x5
randomly constructed matrix.
Your program should print the smallest sum including the index
of its column, and the biggest product including the index of its
row.
In the main function:
- Define and construct 5x5 matrix randomly.
- Pass this matrix to the user defined function
In the user defined function:
- Calculate the sum of elements from every column and
product of elements from every row of the matrix.
- Print the smallest sum including the index of its column,
and the biggest product including the index of its row.
Can you help how to do this homework? I can do it without pointers and functions but i cant do with those.
I started like this but i couldnt continue because i cannot even add the column with a function:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
int a[5][5],i,j;
int *b;
for(i=0;i<5;i++){
for (j=0;j<5;j++){
a[j]=rand()%100;
}}
for(i=0;i<5;i++){
for (j=0;j<5;j++){
printf("%d ",a[j]);
}
printf("\n");
}
int sum=0;
for(j=0;j<5;j++){
for (i=0;i<5;i++){
sum=sum+a[j];
}
printf(" sum=%d\n", sum);
sum=0; }
return 0;
}