Skip to content

Instantly share code, notes, and snippets.

@mr-fool
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save mr-fool/a91d4903c724d282c72e to your computer and use it in GitHub Desktop.

Select an option

Save mr-fool/a91d4903c724d282c72e to your computer and use it in GitHub Desktop.
Calculating compound interest
/*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