Write a symbolic constant or a macro definition for each of the following : 9m Dec2005

By | June 10, 2014

 Write a symbolic constant or a macro definition for each of the following : 9m Dec2005

(i) Define a macro called AREA, which will calculate area of circle in terms of radius. Use the constant PI in calculation.

# include<stdio.h>
# define PI 3.142857
# define AREA(radius) PI * radius * radius
main( )
{
int radius;
printf(“Enter value of radius: ”);
scanf(“%d ”, &radius );
printf(“\nArea is %d”, AREA(radius));
}

# include<stdio.h>
# define PI 3.142857
# define AREA(radius) PI * radius * radius
main( )
{
int radius;
printf(“Enter value of radius:);
scanf(%d ”, &radius );
printf(“\nArea is %d”, AREA(radius));
}
 

(ii) Rewrite the macro described in preceding problem so that radius is expressed as an argument.
# include<stdio.h>
# define AREA(radius) 3.1415 * radius * radius
main( )
{
int radius;
printf(“Enter value of radius: ”);
scanf(“%d ”, &radius );
printf(“\nArea is %d”, AREA(radius));
}

# include<stdio.h>
# define AREA(radius) 3.1415 * radius * radius
main( )
{
int radius;
printf(“Enter value of radius:);
scanf(%d ”, &radius );
printf(“\nArea is %d”, AREA(radius));
}

 (iii) Write a macro called “MAX” that utilizers conditional operator (?: ) to determine maximum of ‘a’ and ‘b’, two integers.

 Solved program can be found on this link http://cssimplified.com/c-programming/a-c-program-that-uses-macros-min-max-to-find-and-return-respectively-the-minimum-maximum-of-two-values

Leave a Reply