

#include <iostream>
using namespace std;
int main()
{
int n;
while(cin >> n)
{
int result = 1;
while(n--)
{
int x;
cin >> x;
if(x % 2 == 1)
{
result *= x;
}
}
cout << result <<endl;
}
return 0;
}
本文介绍了一个使用C++实现的简单程序,该程序从输入的整数中筛选出奇数,并计算这些奇数的乘积。通过while循环和条件判断,程序有效地处理了连续的数字输入,为用户提供了一种计算奇数乘积的方法。


#include <iostream>
using namespace std;
int main()
{
int n;
while(cin >> n)
{
int result = 1;
while(n--)
{
int x;
cin >> x;
if(x % 2 == 1)
{
result *= x;
}
}
cout << result <<endl;
}
return 0;
}
406

被折叠的 条评论
为什么被折叠?