Problem
Write down macro definitions for the following:- To test whether a character entered is a small case letter or not.
- To test whether a character entered is a upper case letter or not.
- To test whether a character is an alphabet or not. Make use of the macros you defined in (1) and (2) above.
- To obtain the bigger of two numbers.
Solution - Code (a)
#include<stdio.h>#include<conio.h>
#include<ctype.h>
#include<string.h>
#define LOWER(ch) (ch>=97&&ch<=122 ? printf("\nlower"):printf("\n not lower"))
main()
{
char ch;
printf("\n enter the character=");
scanf("%c",&ch);
LOWER (ch);
printf ("\npress any key to close.");
getch();
}
Sample Output (a)
Solution - Code (b)
#include<stdio.h>#include<conio.h>
#include<ctype.h>
#include<string.h>
#define UPPER(ch) (ch>=65&&ch<=90 ? printf("\nUpper case"):printf("\n not upper case"))
main()
{
char ch;
printf("\n enter the character=");
scanf("%c",&ch);
UPPER (ch);
printf ("\npress any key to close.");
getch();
}
Sample Output (b)
Solution - Code (c)
#include<stdio.h>#include<conio.h>
#include<ctype.h>
#include<string.h>
#define ALPHA(ch) (isalpha (ch) ? printf("\n alphabet"):printf("\n not alphabet"))
main()
{
char ch;
printf("\n enter the character=");
scanf("%c",&ch);
ALPHA (ch);
printf ("\npress any key to close.");
getch();
}
Sample Output (c)
Solution - Code (d)
#include<stdio.h>#include<conio.h>
#include<ctype.h>
#include<string.h>
#define LARGE(a,b) (a>b ? printf("\n a is greater"):printf("\n b is greater"))
main()
{
int a,b;
printf("\n enter the two number =");
scanf("%d%d",&a,&b);
LARGE (a,b);
printf ("\npress any key to close.");
getch();
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.