/* Write macro for the following :
1. Arithmetic Mean of two no.
2. Absolute value of a no.
3. To convert a Uppercase letter to lower case.
4. To obtain bigger of two numbers.
*/
#include<stdio.h>
#define am(a,b) ((a+b)/2)
#define abs(a) (a>=0?a:-a)
#define ul(ch) (ch>=65 && ch<=96 ? ch+32 : ch)
#define bigger(a,b) (a>=b?a:b)
int main () {
int x,y;
char c;
printf("
Enter two numbers:");
scanf("%d%d",&x,&y);
printf("
The arithmetic mean of two numbers is %f",(float)am(x,y));
printf("
Enter the number:");
scanf("%d",&x);
printf("
The absolute value of the number is %d",abs(x));
printf("
Enter the character:");
scanf("%c",&c);
printf("
The letter in lower case is %c",ul(c));
printf("
Enter two numbers:");
scanf("%d%d",&x,&y);
printf("
The bigger of two numbers is %d",bigger(x,y));
return 0;
}
Everything is working fine except that program does not stop for taking character input.
Here is the snapshot of the output ....
Enter two numbers:4
5
The arithmetic mean of two numbers is 4.000000
Enter the number:-7 **/*After hitting enter here it reaches line no. 7 */**
The absolute value of the number is 7
Enter the character:
The letter in lower case is
Enter two numbers:4 **/*line no. 7*/**
6
The bigger of two numbers is 6
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…