#include <stdio.h> int f(int n) { if(n == 1) return 1; else { return (n + f(n -1)); } } void main() { int sum = 0,n; printf("请输入一个数字"); scanf("%d",&n); sum = f(n); printf("%d", sum); }
时间: 2025-01-03 16:13:43
#include <stdio.h> int f(int n) { if(n == 1) return 1; else { return (n + f(n -1)); } } void main() { int sum = 0,n; printf("请输入一个数字"); scanf("%d",&n); sum = f(n); printf("%d", sum); }