...

/

Example 56: Calculate Interest

Example 56: Calculate Interest

Learn how to calculate interest using macro definitions.

We'll cover the following...

Problem

Write macro definitions with arguments for the calculation of simple interest and total amount. Store these macro definitions in a file called interest.h.

Include this file in your program, and use the macro definitions for calculating simple interest and amount.

Solution

Given below is our recommended way to approach this problem.

Press + to interact
main.c
interest.h
#include <stdio.h>
#include "interest.h"
int main() {
int p, n;
float si, amt, r;
p = 1000; n = 3, r = 15.5;
printf ("The Principal, no. of years and rate of interest is %d, %d and %f respectively.\n",p,n,r);
si = SI (p, n, r);
amt = AMT (p, si);
printf ("Simple interest is: %f\n", si);
printf ("Amount is: %f\n", amt);
return 0;
}

Explanation

It is a simple program that calculates simple interest and the total amount after interest. Initially, we define the macro definitions for the following formulae:

  • Simple interest
  • Amount

The formula to calculate simple interest is:

...