#include "stdio.h"

float f(int n) { float y; if (n==1 || n==0) { y = 1; } else { y = n * f(n-1); // 递归调用 } return y; }

int main() { float s = 0; int i; for(i=1; i<=9; i++) { s += f(i); // 求1!+2!+3!+...+9! } printf("%.0f\n",s); return 0; }

1编写递归函数求n!然后调用该函数求1!+2!+3!+ +9!。#include stdiohfloat fint n float y; if n==1n==0 y=1 ; else 1 ; 2 ;int main float s; int i; 3 ; fori=1;

原文地址: https://www.cveoy.top/t/topic/fpX6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录