Last active
August 29, 2015 14:02
-
-
Save mr-fool/a91d4903c724d282c72e to your computer and use it in GitHub Desktop.
Calculating compound interest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Calculating compound interest*/ | |
| #include <stdio.h> | |
| #include <math.h> | |
| int main (void) { | |
| double amount; | |
| double principal; | |
| double rate; | |
| int year; | |
| int i; | |
| printf("Please enter the principal, rate, year\n"); | |
| scanf("%lf %lf %d",&principal,&rate,&year); | |
| /*Printing the header*/ | |
| printf("%4s%21s\n", "Year","Amount on deposit"); | |
| /*Calculate the amount on deposit for x year*/ | |
| for ( i = 0 ; i <= year; i++) { | |
| /*Calculate new amount for specified year*/ | |
| amount = principal * pow (1.0 + rate, i); | |
| /*Output one table row*/ | |
| printf("%4d%21.2lf\n",i,amount); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment