求助 用递归写程序
用递归求2 4 8 16....的和,当和大于10000时退出 怎么写? 求详细程序 谢谢大神了
程序代码:
#define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> int a(int n,int sum); int main(void) { int n = 1; int sum = 0; printf_s("%d",a(n,sum)); return 0; } int a(int n,int sum) { n = n * 2; sum = sum + n; if (sum <= 1000) { return a(n, sum); } else { return n; } }