Write a ‘C’ program to write a macro definition for the following.
> To test whether a character is a lower case letter or not.
> To check whether a character is alphabet or not.
> To obtain the largest of two numbers.
#include<stdio.h>
#include<conio.h>
#define LOWER(ch) islower(ch)
#define ALPHA(ch) isalpha(ch)
#define MAX(a,b) a>b?a:b
void main()
{
int n,a,b;
char c;
clrscr();
do
{
printf("\n1.LOWER");
printf("\n2.ALPHABET");
printf("\n3.MAXIMUM");
printf("\n4.EXIT");
printf("\nENTER UR CHOICE");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nENTER THE CHARACTER");
c=getche();
if(LOWER(c))
{
printf("\nCHARACTER IS IN LOWERCASE\n");
}
else
{
printf("\nCHARACTER IS IN UPPERCASE");
}
break;
case 2:
printf("\nENTER THE CHARACTER");
c=getche();
if(ALPHA(c))
{
printf("\nCHARACTER IS ALPHABET");
}
else
{
printf("CHARACTER IS NOT ALPHABET");
}
break;
case 3:
printf("\nENTER THE VALUES FOR A AND B");
scanf("%d%d",&a,&b);
if(MAX(a,b))
{
printf("A IS MAXIMUM");
}
else
{
printf("B IS MAXIMUM");
}
break;
case 4:
exit(0);
}
}
while(n!=4);
getch();
}
> To test whether a character is a lower case letter or not.
> To check whether a character is alphabet or not.
> To obtain the largest of two numbers.
#include<stdio.h>
#include<conio.h>
#define LOWER(ch) islower(ch)
#define ALPHA(ch) isalpha(ch)
#define MAX(a,b) a>b?a:b
void main()
{
int n,a,b;
char c;
clrscr();
do
{
printf("\n1.LOWER");
printf("\n2.ALPHABET");
printf("\n3.MAXIMUM");
printf("\n4.EXIT");
printf("\nENTER UR CHOICE");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nENTER THE CHARACTER");
c=getche();
if(LOWER(c))
{
printf("\nCHARACTER IS IN LOWERCASE\n");
}
else
{
printf("\nCHARACTER IS IN UPPERCASE");
}
break;
case 2:
printf("\nENTER THE CHARACTER");
c=getche();
if(ALPHA(c))
{
printf("\nCHARACTER IS ALPHABET");
}
else
{
printf("CHARACTER IS NOT ALPHABET");
}
break;
case 3:
printf("\nENTER THE VALUES FOR A AND B");
scanf("%d%d",&a,&b);
if(MAX(a,b))
{
printf("A IS MAXIMUM");
}
else
{
printf("B IS MAXIMUM");
}
break;
case 4:
exit(0);
}
}
while(n!=4);
getch();
}