计算100到1的阶乘之和c++
#include
using namespace std;
int factorial(int n) { if (n == 0 || n == 1) { return 1; } else { return n * factorial(n - 1); } }
int main() { int sum = 0; for (int i = 100; i >= 1; i--) { sum += factorial(i); } cout << "The sum of factorials from 100 to 1 is: " << sum << endl; return 0; }
原文地址: https://www.cveoy.top/t/topic/igfz 著作权归作者所有。请勿转载和采集!