Question-Write down macro definitions for the following:
1. To find arithmetic mean of two numbers.
2. To find absolute value of a number.
3. To convert a uppercase alphabet to lowercase.
4. To obtain the bigger of two numbers.
Answer-
#include<stdio.h>
#define MEAN(a,b) ((a+b)/2)
#define ABSOL (c>0?printf("Absolute value=%d\n",a):printf("Absolute value=%d\n,-a))
#define CONVERTER(d) (d=d+32)
#define BIG(e,f) (e>f?printf("First number is bigger\n"):printf("Second number is bigger\n"))
/*As the question urges, these are just macro definitions but I recommend you to write solve the full problem because sometimes macro leads us to unpredictable results */
1. To find arithmetic mean of two numbers.
2. To find absolute value of a number.
3. To convert a uppercase alphabet to lowercase.
4. To obtain the bigger of two numbers.
Answer-
#include<stdio.h>
#define MEAN(a,b) ((a+b)/2)
#define ABSOL (c>0?printf("Absolute value=%d\n",a):printf("Absolute value=%d\n,-a))
#define CONVERTER(d) (d=d+32)
#define BIG(e,f) (e>f?printf("First number is bigger\n"):printf("Second number is bigger\n"))
/*As the question urges, these are just macro definitions but I recommend you to write solve the full problem because sometimes macro leads us to unpredictable results */
No comments:
Post a Comment