Compound Interest
Completed
Read principal, yearly rate (%) and years. Print the final amount with yearly compounding (P × (1 + r/100)^years) with 2 decimals.
Input
Three numbers: P r years.
Output
One line.
Example
Input
1000 5 10
Output
1628.89
Editor
C
Hints
pow(base, exponent) from math.h.
Solution explanation
Different placeholders in one scanf read different types in order.
Show solution
#include <stdio.h>
#include <math.h>
int main() {
double p, r;
int years;
scanf("%lf %lf %d", &p, &r, &years);
printf("%.2f\n", p * pow(1 + r / 100, years));
return 0;
}