Question-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.
Solution-
#include<stdio.h>
#define SI(p,n,r) (p*n*r/100)
#define AMOUNT(p,s) (p+s)
int main()
{
int p=1000,n=5;
float s,a,r=8.0;
printf("Enter the value of p,n,r Respectively\n");
scanf("%d%d%f",&p,&n,&r);
s=SI(p,n,r);
a=AMOUNT(p,s);
printf("Simple interest=%f\nTotal Amount=%f\n",s,a);
return 0;
}
/* Here pinkish part indicates the header file content and other black and white part tells the content of main file */
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.
Solution-
#include<stdio.h>
#define SI(p,n,r) (p*n*r/100)
#define AMOUNT(p,s) (p+s)
int main()
{
int p=1000,n=5;
float s,a,r=8.0;
printf("Enter the value of p,n,r Respectively\n");
scanf("%d%d%f",&p,&n,&r);
s=SI(p,n,r);
a=AMOUNT(p,s);
printf("Simple interest=%f\nTotal Amount=%f\n",s,a);
return 0;
}
/* Here pinkish part indicates the header file content and other black and white part tells the content of main file */
No comments:
Post a Comment