使用 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 <<"Product of the Array is:" <<ProductOfArray(m, n);
}輸出
Product of the Array is:42
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP