/* * 假设银行一年整存零取的月息为0.63%。现在某人手中有一笔钱, * 他打算在今后的五年中的年底取出1000元,到第五年时刚好取完, * 请算出他存钱时应存入多少? * * 因为按照本题有如下公式: * 当1<=n<=4 时 * f(n) =( f(n+1)+1000) / (1+0.0063*12) * 当 n=5 时 * f(n) = 1000/(1+0.0063*12) * 所以可以采用递归的算法 */ #include <stdio.h> #include <assert.h> float getTotal(int year) { if(year==5) return 1000/(1+0.0063*12); else return (getTotal(year+1)+1000)/(1+0.0063*12); } int main(void) { int i; float total=0; total = getTotal(1); printf("他的首次存款额最少为 %.2f ?/n",total); return 0; } Output: 1 他的首次存款额最少为 4039.44 元