1.5 15: Bank interest

Description
Farmer John made a lot of money last year! He wants to invest the money and is curious about how much he can get. It is known that the compound annual interest rate of investment is R (an integer between 0 and 20). John has money with a total value of M (an integer between 100 and 1,000,000). He clearly knows that he wants to invest in Y years (range 0 to 400). Please help him calculate how much money he will eventually have and output the integer part of it. The data guarantee that the output result is in the range of 32-bit signed integer.

Input
One line contains three integers R, M, Y, separated by a single space between two adjacent integers.
Output
an integer, which is how much money John ultimately owns (integer part).
Sample input
5 5000 4
Sample output
6077
prompt
In the sample
, after the first year: 1.05 * 5000 = 5250 After the
second year: 1.05 * 5250 = 5512.5 After the
third year: 1.05 * 5512.50 = 5788.125 After the
fourth year : 1.05 * 5788.125 =
6077.53125 The integer part of 6077.53125 is 6077.
Source
USACO 2004 November

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    
    
	int R,Y;
	double M, rate;
	cin>>R>>M>>Y;
	rate = R*0.01;
	for(int i=0;i<Y;i++)
	{
    
    
		M = (1+rate)*M;
	}
	printf("%d",(int)M);
	return 0;
}

Guess you like

Origin blog.csdn.net/yansuifeng1126/article/details/111999441