我已经尝试过几次分析我的代码,但仍然找不出为什么当输入10-20时它没有显示“产品在几十”。
#include <iostream>
using namespace std;
int main()
{
int n, t;
double f = 1;
cout << "Input a digit: ";
cin >> n;
cout << n << "! is: ";
for (t = 1; t <= n; t++) {
f = f * t;
cout << t;
if (n > t) {
cout << " x ";
}
else {
cout << " = " << f << endl;
}
}
if (f < 10) {
cout << "The product is in ones." << endl;
}
if ((f < 100) == (f > 10)) {
cout << "The product is in tens." << endl;
}
if ((f < 1000) == (f > 100)) {
cout << "The product is in hundreds." << endl;
}
if ((f < 10000) == (f > 1000)) {
cout << "The product is in thousands." << endl;
}
return 0;
}比方说,输入在10到20之间。
Input: 10
Result: 10! is:1x2x3x4x5x6x7x8x9x10=3628800不是应该说“这个产品有几十块吗?”
通常,如果我输入,比如说,'5',结果会是:
5! is:1x2x3x4x5=120
the product is in hundreds编辑:我发现了一个小问题,它应该在“产品在[]”上大写'T‘,但是它反而导致了"the“,即小写字母”t“应该是大写字母。
发布于 2022-01-22 00:35:14
正如您的代码所指出的:
10! == 1x2x3x4x5x6x7x8x9x10 == 3,628,800这个数字是几百万,而不是数千万。因此,条件失败是有意义的,因为3628800不少于100。
https://stackoverflow.com/questions/70808976
复制相似问题