Help for pointers and matrix


Joined
Apr 28, 2012
Messages
1
Reaction score
0
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;

}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top