/* 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("\nEnter two numbers:");
scanf("%d%d",&x,&y);
printf("\nThe arithmetic mean of two numbers is %f",(float)am(x,y));
printf("\nEnter the number:");
scanf("%d",&x);
printf("\nThe absolute value of the number is %d",abs(x));
printf("\nEnter the character:");
scanf("%c",&c);
printf("\nThe letter in lower case is %c",ul(c));
printf("\nEnter two numbers:");
scanf("%d%d",&x,&y);
printf("\nThe bigger of two numbers is %d",bigger(x,y));
return 0;
}
Все работает нормально, за исключением того, что программа не останавливается для ввода символов.
Вот снимок вывода ....
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