Thursday, 21 June 2012

write a c programto arite macro defination


/*write a c programto arite macro defination for the
following
a)to check whether a character is lower case or not
b)to check whether a character is alphabet or not
c)to obtain the largest of two number
*/
#include<stdio.h>
#include<conio.h>
#define ISALPHA
#define ISLOWER
#define GREAT
void main()
{
char ch;
int a,b;
int choice=0;
clrscr();
while(1)
{
printf("\n1 :alphabet");
printf("\n2 :lowercase");
printf("\n3 :greater");
printf("\nenter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1:flushall();
       printf("\nenter any character :");
       scanf("%c",&ch);
       if(isalpha(ch))
       printf("\nit is an alphabet :");
       else
       printf("\nit is not an alphabet :");
       getch();
       break;
case 2:flushall();
       printf("\nenter any character :");
       scanf("%c",&ch);
       if(islower(ch))
       printf("\nit is lower case :");
       else
       printf("\nit is not a lower case : ");
       getch();
       break;
case 3:printf("\nenter any two number : ");
       scanf("%d%d",&a,&b);
       if(GREAT(a>b))
       printf("\na is greater :");
       else
       printf("\nb is greater :");
       getch();
       break;
}
}
}

/*
1 :alphabet
2 :lowercase
3 :greater
enter your choice1

enter any character :a

it is an alphabet : */
/*
1 :alphabet
2 :lowercase
3 :greater
enter your choice2

enter any character :1

it is not a lower case :*/
/*
1 :alphabet                                                                  
2 :lowercase                                                                  
3 :greater                                                                    
enter your choice3                                                            
                                                                             
enter any two number : 2                                                      
1                                                                            
                                                                             
a is greater :                                                                
*/

No comments: