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

C Program To Calculate Amount In Compound Interest

When interest compounds q times per year at an annual rate of r % for n years, the principal p compounds to an amount a as per the following formula:

a = p (1 + r / q) nq

Write a C Program to read 10 sets of p, r, n & q and calculate the corresponding a‘s.

Related Read:
Basic Arithmetic Operations In C
For Loop In C Programming Language
C Program to Calculate the Compound Interest

Video Tutorial: C Program To Calculate Amount In Compound Interest


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

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


Logic To Find Compounded Amount

We ask the user to enter values for floating point variables p, n, r and q. We use the formula:

a = p (1 + r / q) nq

And display the result to the console window.

where,
p – principal amount;
n – number of years.
r – rate of interest;
q – number of times interest compounds per year.

Note: We need to convert the user entered interest into percentage by dividing the integer number by 100.

Source Code: C Program To Calculate Amount In Compound Interest

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

int main()
{
    float p, n, r, q, a;
    int count;

    for(count = 1; count <= 10; count++)
    {
        printf("Enter principal amount\n");
        scanf("%f", &p);

        printf("Enter number of years\n");
        scanf("%f", &n);

        printf("Enter rate of interest\n");
        scanf("%f", &r);

        r = r / 100;

        printf("Enter no of times you compound per year\n");
        scanf("%f", &q);

        a = p * pow( (1 + (r/q)), n * q );

        printf("Compounded amount is %f\n\n", a);
    }

    return 0;
}

Output
Enter principal amount
5000
Enter number of years
2
Enter rate of interest
8
Enter no of times you compound per year
4
Compounded amount is 5858.296875

Enter principal amount
1000
Enter number of years
7
Enter rate of interest
5
Enter no of times you compound per year
1
Compounded amount is 1407.100464

Enter principal amount
2000
Enter number of years
5
Enter rate of interest
12
Enter no of times you compound per year
12
Compounded amount is 3633.393311

Enter principal amount
5000
Enter number of years
5
Enter rate of interest
5
Enter no of times you compound per year
5
Compounded amount is 6412.160156

Enter principal amount

Note: Above program keeps on iterating 10 times and asks the input 10 times.

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

C Program to Calculate the Compound Interest

In this video tutorial lets learn how we can calculate Compound Interest by making use of simple arithmetic operations.

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

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

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

    printf("Enter rate of interest\n");
    scanf("%f", &r);

    printf("Enter time period\n");
    scanf("%d", &t);


    ci = p * pow( (1 + r / 100), t );

    printf("Compound Interest is %f\n", ci);

    return 0;
}

Output:
Enter principal amount
1000
Enter rate of interest
8.5
Enter time period
3
Compound Interest is 1277.289185

Note: Since we’re using pow() method, we need to include math.h library file.

Scanf(): For user input

In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program

C Program to Calculate the Compound Interest


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

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


In this program we take input for Principal amount, rate of interest and time period from the user, and then calculate Compound Interest for those values.

Compound Interest Logic




We make use of arithmetic operations available in C programming language and convert this formula to calculate Compound Interest.

Compound_Interest = Principal_amount * pow( (1 + r / 100), t );

This gives us Compound Interest and we output the result to the console.

Formula for calculating Compound Interest

p – Principal amount.
r – Rate of interest.
t – Time period.
ci – Compound Interest.

Yearly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + r / 100), t );

Half-Yearly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + (r/2) / 100), 2 * t );

Quarterly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + (r/4) / 100), 4 * t );

Monthly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + (r/12) / 100), 12 * t );

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

C Program to Calculate the Simple Interest

In this video tutorial lets learn how we can calculate Simple Interest by making use of simple arithmetic operations.

 
#include<stdio.h>

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

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

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

    printf("Enter time period\n");
    scanf("%d", &t);

    si = (p * t * r) / 100.0;

    printf("Simple Interest is %f\n", si);

    return 0;
}

Output:
Enter principal amount
1000
Enter Rate of interest
14
Enter time period
2
Simple Interest is 280.000000

Scanf(): For user input

In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program

C Program to Calculate the Simple Interest


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

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


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.

Simple Interest Logic




We make use of arithmetic operations available in C programming language and convert this formula to calculate Simple Interest.

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

This gives us Simple Interest and we output the result to the console.

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