Calculating the compound interest for 20 years for the given data in C programming using for loop

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Calculating the compound interest for 20 years for the given data in C programming using for loop

To show: Using for loop to calculate the compound interest of the given principal

 

 

// Using 'for' loop to calculate compound interest

#include <stdio.h>

// for the pow() function

#include <math.h>

 

int main(void)

{

int year;

double amount, principal = 1000.0, rate = 0.34;

 

printf("Principal = 1000.00; rate p/a = 0.34\n");

printf("Let see how much money you will generate in 20 years!\n\n");

printf("%4s%21s\n", "Year", "Amount on deposit");

 

for(year = 1; year <= 20; year++)

{

amount = principal * pow(1.0 + rate, year);

printf("%4d%21.2f\n", year, amount);

}

return 0;

}

 

Output example:

 

Principal = 1000.00; rate p/a = 0.34

Let see how much money you will generate in 20 years!

Year Amount on deposit

1            1340.00

2            1795.60

3            2406.10

4            3224.18

5            4320.40

6            5789.34

7            7757.71

8            10395.33

9            13929.75

10          18665.86

11          25012.25

12          33516.42

13          44912.00

14          60182.08

15          80643.98

16         108062.94

17         144804.34

18         194037.81

19         260010.67

20         348414.30

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index