使用STL的C ++阵列产品
这是一个C++程序的示例,用于查找数组产品。
算法
Begin Initialize the values of array. Call used defined function accumulate to return the product of array. Print the solution. End.
范例程式码
#include <iostream>
#include <numeric>
using namespace std;
int ProductOfArray(int p[], int n) {
return accumulate(p, p + n, 1, multiplies<int>());
}
int main() {
int m[] = {6,7 };
int n = sizeof(m) / sizeof(m[0]);
cout <<"数组的乘积为:" <<ProductOfArray(m, n);
}输出结果
数组的乘积为:42