C Program to Calculate Simple Interest and Amount using Macros

Problem Statement: Write macro definitions with arguments for calculation of Simple Interest and 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.

Related Read:
Macros With Arguments: C Program
C Program to Calculate the Simple Interest

Video Tutorial: C Program to Calculate Simple Interest and Amount using Macros


[youtube https://www.youtube.com/watch?v=uzi8Dkv0ncM]

YouTube Link: https://www.youtube.com/watch?v=uzi8Dkv0ncM [Watch the Video In Full Screen.]

Source Code: C Program to Calculate Simple Interest and Amount using Macros

interest.h

#define SI(p, t, r)  ( (p * t * r) / 100.0 )
#define AMT(p, t, r) ( SI(p, t, r) + p )

main.c

#include<stdio.h>

#include "interest.h"

int main()
{
    float p, t, r;

    printf("Enter principal amount\n");
    scanf("%f", &p);

    printf("Enter Rate of Interest\n");
    scanf("%f", &r);

    printf("Enter Time Period\n");
    scanf("%f", &t);

    printf("Simple Interest: %0.2f\n", SI(p, t, r));
    printf("Total Amount: %0.2f\n", AMT(p, t, r));

    return 0;
}

Output:
Enter principal amount
1000
Enter Rate of Interest
9.2
Enter Time Period
2
Simple Interest: 184.00
Total Amount: 1184.00

In this program we take input for Principal amount, rate of interest and time period from the user, and then calculate Simple Interest for those values and also the total amount accumulated after getting simple interest.

Simple Interest Logic

Simple_Interest = ( Principal_amount * Rate_of_interest * Time ) / 100.0;

Amount = Simple_Interest + Principal_amount;

Note: In Simple Interest formula we are dividing by 100.0 because the ( Principal_amount * Rate_of_interest * Time ) might yield a floating / double type value, so if we divide it by integer 100 then it might give wrong result.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert