Question #37614

Write a function in C++ to print the product of each column of a two dimensional integer array passed as the argument of the function.
Explain : If the two dimensional array contains
1 2 4
3 5 6
4 3 2
2 1 5
The output should appear as :
Product of Column 1 = 24
Product of Column 2 = 30
Product of Column 3 = 240
1

Expert's answer

2013-12-10T09:34:29-0500

Answer on Question#37614 - Programming, C++

1. Write a function in C++ to print the product of each column of a two dimensional integer array passed as the argument of the function.

Explain: If the two dimensional array contains


1 2 4
3 5 6
4 3 2
2 1 5


The output should appear as:


Product of Column 1 = 24
Product of Column 2 = 30
Product of Column 3 = 240


Solution.


#include <iostream>
using namespace std;
void output(int (*arr)[3]);
int main(int argc, char* argv[])
{
    int arr[4][3] = {{1, 2, 4},
                     {3, 5, 6},
                     {4, 3, 2},
                     {2, 1, 5}};
    output(arr);
    system("pause");
    return 0;
}
void output(int (*arr)[3])
{
    int product = 1;
    for(int j = 0; j < 3; j++)
    {
        for(int i = 0; i < 4; i++)
        {
            product *= arr[i][j];
        }
        cout << "Product of Column " << j + 1 << " = " << product << endl;
        product = 1;
    }
}


d:DataBase\QQ\Debug\QQ.exe

□ □ X

Product of Column 1 = 24

Product of Column 2 = 38

Product of Column 3 = 248


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS