Answer on Question#37627, Programming, C++
#include<iostream>
using namespace std;
void product(int *arr[2], int number); // prototype of function product
void product(int *arr[2], int number) { // function product
int product = 1;
for (int i = 0; i < 2; i++) {
product = 1;
for (int j = 0; j < number; j++) {
product *= arr[j][i];
}
cout << "Product of " << i + 1 << " column : " << product;
cout << endl;
}
}
int main() {
int number;
cout << "Please enter amount of numbers in array : ";
cin >> number;
cout << endl;
int **arr = new int *[number]; // allocate memory for array
for (int i = 0; i < number; i++) {
arr[i] = new int[2];
for (int j = 0; j < 2; j++) {
cout << "Please enter the numbers of the " << i + 1 << " column : ";
cin >> arr[i][j]; // input array
cout << endl;
}
}
product(arr, number); // pass the array and number of numbers to the function
delete []arr; // clear memory
system("pause");
return 0;
}
Comments