training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

getrate2.c (531B)


      1 /* Esercizio 4.15 */
      2 
      3 #include <stdio.h>
      4 #include <math.h>
      5 
      6 int main()
      7 {
      8    int amount;
      9    int principal = 1000;
     10    double rate = 0.5;
     11    int year, rest, rest2;
     12 
     13    printf("%4s%21s\n", "Year", "Amount of deposit");
     14    for (year = 1; year <= 10; year++) {
     15 
     16       amount = principal * pow(1 + rate, year); 
     17       rest = rest2 = principal * pow(1 + rate, year) * 100;
     18       rest = (int) rest / 10 % 10; 
     19       rest2 = (int) rest2 % 10; 
     20 
     21       printf("%4d%18d.%d%d\n", year, amount, rest, rest2);
     22    }
     23 
     24    return 0;
     25 } /* E0F main */
     26