大佬们可不可以帮我解答一下,谢谢
1+1/2+1/3+1/4+…+1/50,加到绝对值小于1e-6,用递归求和.
#include <stdio.h> double recursion(int n); int main() { double sum=0; int n=1; sum=recursion(n); printf("sum=%lf",sum); return 0; } double recursion(int n) { //printf("n=%lf\n",(double)1.0/n); if((double)1.0/n<(1e-4)) return (double)1.0/n; else return (double)1.0/n+recursion(n+1); }