The problem of saving money

Source: Internet
Author: User

"Problem description"

Father prepared for the Little Dragon's four college life one-time savings of a sum of money, using the whole deposit 0 to take the way to control the little dragons at the beginning of each month to take 1000 yuan to prepare for this month use. Assuming that the bank deposits 0 per annum at an annual interest of 1.71%, please figure out how much money the father needs to deposit at least.

"Problem Analysis"

This problem is a typical recursive problem, the analysis of the process of saving money and to withdraw funds, we can adopt the method of inverse push. 4 years and 48 months, 1000 yuan a month, the last one months just take it out. We can use an array to hold the remaining amount of money for each month, then the last one months with a 1000, that is, the 48th month in the array value is 1000.

The 47th month Passbook money is: Take away 1000 yuan living expenses + next month 1000 months of principal, namely:

1000+ 48th Month's money/(1+0.00171/12)

The sum of the 46th, three 、......、 1th months can be calculated by analogy:

The money in the passbook for the 46th month is: 1000+ the 47th month (1+0.00171/12)

The money in the passbook for the 45th month is: 1000+ the 46th month (1+0.00171/12)

......

The money in the passbook for the 1th month is: 1000+ the 2nd month (1+0.00171/12)

The amount of the initial deposit can be calculated by the above recursive push.

"Program Code"

1  Public classCQWT2 {  3      Public Static  Final  Doublemoneyrate=0.0171;//Deposit Rate4      Public Static voidMain (string[] args)5     {  6         //define an array of length 48 to fill the remaining deposits at the beginning of each month7         Doublemoney[]=New Double[48]; 8           9         //1000 Yuan at the beginning of the last one monthsTenmoney[47]=1000;  OneSystem.out.printf ("Number of remaining deposits at the beginning of 48:%.2f\n", money[47]);  A         //the remaining deposits in the previous one months are rolled out by cyclic reversal -          for(inti=47;i>0;i--)   -         {   themoney[i-1]=1000+money[i]/(1+MONEYRATE/12);  -System.out.printf ("Number of remaining deposits at the beginning of the month of%d:%.2f\n", i,money[i-1]);  -         }   -         //calculate the amount of money that was originally deposited, that is, the first remaining deposit +System.out.printf ("\ n originally to deposit%.2f yuan. ", money[0]);  -     }   +}

"Run Results"

The problem of saving money

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.