
各位帮忙看看那块错了
C语言大一新生,求详解
C语言大一新生,求详解
C语言大一新生,求详解
关注你的内层循环中使用了l变量来统计乘方的次数,但在外层循环中却没有将其置0,下面给出了一个正确的参考代码。
#include <iostream>
int main() {
int m, n;
std::cout << "Enter the values of m and n: ";
std::cin >> m >> n;
long long result = 0; // 用于存储结果
int i = 1;
while (i <= n) { // 从 1 到 n 循环
long long term = 1; // 用于存储当前项
int j = 0;
while (j < m) { // 计算当前项的值
term *= (2 * i);
j++;
}
result += term; // 将当前项加到结果中
i++;
}
std::cout << "Result: " << result << std::endl;
return 0;
}
如还有不懂可以追问,如问题解决请采纳