Macros With Arguments
If required arguments can be passed in macros
Example:1
C program to take input for a character check and print whether the character is an alphabet or not?
#include<stdio.h>
//#include<conio.h>
#define and &&
#define or ||
#define alpha(n) ((n>='A' and n<='Z') or (n>='a' and n<='z'))//1
int main()
{
char ch;
//clrscr();
printf("Enter any character ");
ch=getchar();//scanf("%c",&ch);
if (alpha(ch)) //2
printf("It is an alphabet\n");
else
printf("it is not an alphabet\n");
return(0);
}
Example:2
C program to take input for a character check and print whether the character is an upper case alphabet or not?
Sol:
#include<stdio.h>
//#include<conio.h>
#define and &&
#define or ||
#define upper(n) (n>='A' and n<='Z')//1
int main()
{
char ch;
//clrscr();
printf("Enter any character ");
ch=getchar();//scanf("%c",&ch);
if (upper(ch)) //2
printf("It is an upper case alphabet\n");
else
printf("it is not an upper case alphabet\n");
return(0);
}
/* Output */ Enter any character k it is not an upper case alphabet Enter any character D It is an upper case alphabet
Example:3
C program to take input for a character check and print whether the character is a lower case alphabet or not?
Sol:
#include<stdio.h>
//#include<conio.h>
#define and &&
#define or ||
#define lower(n) (n>='a' and n<='z')//1
int main()
{
char ch;
//clrscr();
printf("Enter any character ");
ch=getchar();//scanf("%c",&ch);
if (lower(ch)) //2
printf("It is a lower case alphabet\n");
else
printf("it is not a lower case alphabet\n");
return(0);
}
/* Output */ Enter any character h It is a lower case alphabet Enter any character A it is not a lower case alphabet
Example:4
C program to take input for a character check and print whether the character is a digit or not?
Sol:
#include<stdio.h>
//#include<conio.h>
#define and &&
#define or ||
#define digit(n) (n>='0' and n<='9')//1
int main()
{
char ch;
//clrscr();
printf("Enter any character ");
ch=getchar();//scanf("%c",&ch);
if (digit(ch)) //2
printf("It is a digit\n");
else
printf("it is not a digit\n");
return(0);
}
/* Output */ Enter any character 5 It is a digit Enter any character d it is not a digit
Example:5
C program to take input for a character check and print whether the character is a vowel or not?
Sol:
#include<stdio.h>
//#include<conio.h>
#define and &&
#define or ||
#define vowel(n) (n=='A' or n=='a' or n=='E' or n=='e' or n=='I' or n=='i' or n=='O' or n=='o' or n=='U' or n=='u')//1
int main()
{
char ch;
//clrscr();
printf("Enter any character ");
ch=getchar();//scanf("%c",&ch);
if (vowel(ch)) //2
printf("It is a Vowel\n");
else
printf("it is not a Vowel\n");
return(0);
}
/* Output */ Enter any character e It is a Vowel Enter any character O It is a Vowel Enter any character d it is not a Vowel




