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 Compute Smallest Number of Notes That Will Combine To Give Rs N

Consider a currency system in which there are notes of seven denominations, namely, Re 1, Rs 2, Rs 5, Rs 10, Rs 50 and Rs 100. If a sum of Rs N is entered through the keyboard, write a C program to compute the smallest number of notes that will combine to give Rs N.

Related Read:
Basic Arithmetic Operations In C

Logic To Get Minimum Number of Notes To Represent The Amount

First we divide the user entered amount with the biggest denomination i.e., Rs 100. Next, if its divisible, then we subtract the number of Rs 100 currency notes we get by dividing the amount by 100. Next we check for the next biggest denomination Rs 50 and so on ..Rs 10, Rs 5, Rs 2 and Rs 1.

Source Code: C Program To Compute Smallest Number of Notes That Will Combine To Give Rs N

 
#include < stdio.h >

int main()
{
    int amount, temp;

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

    temp   = amount / 100;
    amount = amount - (temp*100);

    printf("%d   x 100 = %d\n", temp, (temp*100));

    temp   = amount / 50;
    amount = amount - (temp*50);

    printf("%d   x 50  = %d\n", temp, (temp*50));

    temp   = amount / 10;
    amount = amount - (temp*10);

    printf("%d   x 10  = %d\n", temp, (temp*10));

    temp   = amount / 5;
    amount = amount - (temp*5);

    printf("%d   x 5   = %d\n", temp, (temp*5));

    temp   = amount / 2;
    amount = amount - (temp*2);

    printf("%d   x 2   = %d\n", temp, (temp*2));

    temp   = amount / 1;
    amount = amount - (temp*1);

    printf("%d   x 1   = %d\n", temp, (temp*1));

    return 0;
}

Output 1:
Enter amount
123
1 x 100 = 100
0 x 50 = 0
2 x 10 = 20
0 x 5 = 0
1 x 2 = 2
1 x 1 = 1

Output 2:
Enter amount
2000
20 x 100 = 2000
0 x 50 = 0
0 x 10 = 0
0 x 5 = 0
0 x 2 = 0
0 x 1 = 0

Output 3:
Enter amount
123456
1234 x 100 = 123400
1 x 50 = 50
0 x 10 = 0
1 x 5 = 5
0 x 2 = 0
1 x 1 = 1

C Program To Compute Smallest Number of Notes That Will Combine To Give Rs N


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

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


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