C ++中数字数组的乘积中的第一个数字
在本教程中,我们将学习如何查找数组乘积的第一位。
让我们看看解决问题的步骤。
初始化数组。
在数组中查找元素的乘积。
将结果除以小于10的结果。
打印一位数字
示例
让我们看一下代码。
#include <bits/stdc++.h>
using namespace std;
int productOfArrayDigits(int arr[], int n) {
int product = 1;
for (int i = 0; i < n; i++) {
product *= arr[i];
}
return product;
}
int firstDigitOfNumber(int n) {
while (n >= 10) {
n /= 10;
}
return n;
}
int main() {
int arr[] = { 1, 2, 3, 4, 5, 6 };
cout << firstDigitOfNumber(productOfArrayDigits(arr, 6)) << endl;
return 0;
}输出结果如果运行上面的代码,则将得到以下结果。
7
结论
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下