Chapter - 8: The C Preprocessor

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.


C
Sections
5
Exercises
#include<stdio.h>
#include<conio.h>
#include "interest.h"

int main()
{
	float p, t, r, si, amnt;
	printf("Enter the principal, time in year and rate of interest : ");
	scanf("%f%f%f", &p, &t, &r);
	si = SI(p, t, r);
	amnt = AMOUNT(si, p);
	printf("\nSimple Interest : %f\nAmount : %f", si, amnt);
	_getch();
	return 0;
}

Make a file interest.h and put it in the folder where this file is.

Codes of interest.h

#define SI(a,b,c) ((a*b*c)/100.0)
#define AMOUNT(si,p) (si+p)
 

© 2020 Garbage Valuegarbage value logo