A program to calculate the area and perimeter of the rectangle using macro.
A program to calculate the area and perimeter of the rectangle using macro.
Codes
/*A program to calculate the area and perimeter of the rectangle using macro*/
/*Programed by Jitendra Kr Yadav
10116
15 Mar,2011*/
#include<stdio.h>
#include<conio.h>
#define AREA l*b
#define PERIMETER 2*(l+b)
main()
{
int l,b;
printf(“Enter the length and bredth of the rectangle:\n”);
scanf(“%d%d”,&l,&b);
printf(“Area = %d”,AREA);
printf(“Perimeter = %d”,PERIMETER);
printf(“Press any key to continue…”);
getch();
}
Output
Enter the length and breadth of the rectangle:
15
6
Area = 90
Perimeter = 42
Press any key to continue…
Comments (1)
I think there is different way to #define a simple macro. just saying ine AREA l*b is not working.
please can you explain why?