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 5The output should appear as:
Product of Column 1 = 24
Product of Column 2 = 30
Product of Column 3 = 240Solution.
#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
Comments