If your boss gives you one yuan on the first day, he will give you double the amount of the previous day every day. That is 1, 2, 4, 8.... . Now, after 30 days, how much money have you received in total?
Requirements: Use recursive functions to implement
The problem is very simple, the key lies in the idea, the following is the code.
Haha, shame, I read the wrong question
day 1: salary[1] total[1]
day 2: salary[2] total[3]
day 3: salary[4] total[7]
day 4: salary[8] total[15]
day 5: salary[16] total[31]
day 6: salary[32] total[63]
day 7: salary[64] total[127]
day 8: salary[128] total[255]
day 9: salary[256] total[511]
day 10: salary[512] total[1023]
day 11: salary[1024] total[2047]
day 12: salary[2048] total[4095]
day 13: salary[4096] total[8191]
day 14: salary[8192] total[16383]
day 15: salary[16384] total[32767]
day 16: salary[32768] total[65535]
day 17: salary[65536] total[131071]
day 18: salary[131072] total[262143]
day 19: salary[262144] total[524287]
day 20: salary[524288] total[1048575]
day 21: salary[1048576] total[2097151]
day 22: salary[2097152] total[4194303]
day 23: salary[4194304] total[8388607]
day 24: salary[8388608] total[16777215]
day 25: salary[16777216] total[33554431]
day 26: salary[33554432] total[67108863]
day 27: salary[67108864] total[134217727]
day 28: salary[134217728] total[268435455]
day 29: salary[268435456] total[536870911]
day 30: salary[536870912] total[1073741823]
My idea is: first calculate the current amount, and then pass today's date and amount until the calculation reaches 30 days.
Then call
total()
: