Simple Interest calculation


In this C programming tutorial, i will be showing you how to write a program in C to calculate simple interest; and we are going to need an illustrated example to enable us get variable to use for the calculation. 

So lets assume a person invests $4016.25 in a savings account yielding 9% interest; Assuming that all interest is left on deposit in the account, we are to write a program in C that calculates and prints the amount of money in the account at the end of each year for 5 years.

Formula for calculating simple interest amount is: 

a= p(1+r)n

a= Amount  p= original amount(Principal),  r = Rate ,  n= Number of years.

This problem involves a loop that performs the indicated calculation for each of the 5 years the money remains on deposit.

We would also be using the  [pow]-Standard Library Function. The function pow(x,y) calculates the values of x raised to the yth power.

The header <math.h> should always be included when ever a math function as pow is used


#include<stdio.h>
#include<stdlib.h>
#include<math.h>


int main(void)
{

    double amount; 
    double principal= 4016.25;  
    double rate = 0.9;
    int year ;  

    printf("%3s%17s\n", "YEAR", "AMOUNT");


    for(year=1; year<=5; year++){

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

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

    }

    return 0;

Comments

Popular posts from this blog

Body Mass Index Calculator In C

Adding two Integers in Java Application

Calculating Product, sum, difference, and quotient of Five Integers