Write a 'C' program to write a macro definition for the following i) To test whether a character is a lower case letter or not. ii) To check whether a character is alphabet or not. iii) To obtain the largest of two numbers.
#include<stdio.h> #define ISUPPER(x) (x >= 65 && x <= 90 ? 1 : 0) #define ISLOWER(x) (x >= 97 && x <= 122 ? 1 : 0) #define ISALPHA(x) (ISUPPER(x) || ISLOWER(x)) #define BIG(x,y) (x > y ? x : y) void main() { char ch; int d,a,b; clrscr(); printf("ENTER ANY CHARACTER OR ALPHABET\n"); scanf("%c",&ch); if((d = ISUPPER(ch)) == 1) { printf("\nYOU ENTERED A CAPITAL LETTER."); } else if((d = ISLOWER(ch)) == 1) { printf("\nYOU ENTERED A SMALL LETTER."); } else if((d = ISALPHA(ch)) != 1) { printf("\nYOU ENTERED CHARACTER IS NOT ALPHABET."); } printf("\nENTER ANY 2 NUMBERS::>\n "); scanf("%d%d",&a,&b); d = BIG(a,b); printf("\nBIGGER NUMBERS::> %d",d); getch(); } /*OUTPUT:: ENTER ANY CHARACTER OR ALPHABET A YOU ENTERED A CAPITAL LETTER. ENTER ANY 2 NUMBERS::> 3 2 BIGGER NUMBERS::> 3 ENTER ANY CHARACTER OR ALPHABET g YOU ENTERED A SMALL LETTER. ENTER ANY 2 NUMBERS::> 6 4 BIGGER NUMBERS::> 6
Write a 'C' program to write a macro definition for the following i) To test whether a character is a lower case letter or not. ii) To check whether a character is alphabet or not. iii) To obtain the largest of two numbers.
Reviewed by
on
April 24, 2015
Rating: