Use recursive functions to do the following topics

Source: Internet
Author: User
    1. Zhang San at the beginning of the year to recharge the oil card 20000 yuan, known Zhang San every month will refuel 4 times, the cost is 350*4 yuan.
      Zhang San refueling every 10 times, the petrol station will play once 80 percent, and return to the present 10 percent. Q: Zhang San this card a few times after refueling to recharge again? How much is the oil card balance after each refueling?

      1. Xiao Wang's parents at the beginning of the school to save him 20000 dollars of living expenses, known to the small Wang every month after the bank to take the money 1500 yuan. Suppose the current monthly interest rate is 0.32%.
        So how much does Xiao Wang balance after each time he takes the money? How many times does Xiao Wang finish?

      1. Use recursion to output the following numbers

      5, 3, 1, 3, 5

Reply content:

    1. Zhang San at the beginning of the year to recharge the oil card 20000 yuan, known Zhang San every month will refuel 4 times, the cost is 350*4 yuan.
      Zhang San refueling every 10 times, the petrol station will play once 80 percent, and return to the present 10 percent. Q: Zhang San this card a few times after refueling to recharge again? How much is the oil card balance after each refueling?

      1. Xiao Wang's parents at the beginning of the school to save him 20000 dollars of living expenses, known to the small Wang every month after the bank to take the money 1500 yuan. Suppose the current monthly interest rate is 0.32%.
        So how much does Xiao Wang balance after each time he takes the money? How many times does Xiao Wang finish?

      1. Use recursion to output the following numbers

      5, 3, 1, 3, 5

First question:

 !--? php $total = 20000;function myoil ($total, $times =0) {$times + +;    if ($times%10!=0) {$total = $total-350;    }else{$total = $total -350*0.7; Hit 80 percent and then return 10 percent, understood to hit 70 percent} Echo $times. " Times, and left ". $total."    
   
     "; if (($times%10!=0 && $total <350) | | ($times%10 ==0 && $total <350*0.7))    {return false;    }else{Myoil ($total, $times); }}myoil ($total);? 
    

Results:
1 times, 19650 left.
2 times, 19300 left.
3 times, 18950 left.
4 times, 18600 left.
5 times, 18250 left.
6 times, 17900 left.
7 times, 17550 left.
8 times, 17200 left.
9 times, 16850 left.
10 times, 16605 left.
11 times, 16255 left.
12 times, 15905 left.
13 times, 15555 left.
14 times, 15205 left.
15 times, 14855 left.
16 times, 14505 left.
17 times, 14155 left.
18 times, 13805 left.
19 times, 13455 left.
20 times, 13210 left.
21 times, 12860 left.
22 times, 12510 left.
23 times, 12160 left.
24 times, 11810 left.
25 times, 11460 left.
26 times, 11110 left.
27 times, 10760 left.
28 times, 10410 left.
29 times, 10060 left.
30 times, 9815 left.
31 times, 9465 left.
32 times, 9115 left.
33 times, 8765 left.
34 times, 8415 left.
35 times, 8065 left.
36 times, 7715 left.
37 times, 7365 left.
38 times, 7015 left.
39 times, 6665 left.
40 times, 6420 left.
41 times, 6070 left.
42 times, 5720 left.
43 times, 5370 left.
44 times, 5020 left.
45 times, 4670 left.
46 times, 4320 left.
47 times, 3970 left.
48 times, 3620 left.
49 times, 3270 left.
50 times, 3025 left.
51 times, 2675 left.
52 times, 2325 left.
53 times, 1975 left.
54 times, 1625 left.
55 times, 1275 left.
56 times, 925 left.
57 times, 575 left.
58 times, 225 left.

The following principle is identical

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.