Thursday 26 July 2012

Conditional statement016


Any character is entered through the keyboard; write a program to determine whether the character entered is a capital letter, a small letter, a digit or a special symbol.
The following table shows the range of ascii values for various characters.

Characters
Ascii Values
A – Z

a – z

0 – 9

Special symbols
65 – 90

97 – 122

48 – 57

0 – 47, 58 – 64, 91 – 96, 123 – 127


#include <stdio.h>
#include <conio.h>
void main ( )
{      
        char       ch;
        clrscr ( );
         
        printf ("\n\n\n\t\t Enter a character from the keyboard .....: "); scanf ("%c",&ch);
              
        if ( ch >= 65 && ch <= 90 )
        {                    
                    printf ("\n\n\n\t\t The character is an uppercase letter.");
        }                     
        if ( ch >= 97 && ch <= 122 )
        {                    
                    printf ("\n\n\n\t\t The character is a lowercase letter.");
        }                         
        if ( ch >= 48 && ch <= 57 )
        {                              
                    printf ("\n\n\n\t\t The character is a digit letter.");
        }                                          
        if (( ch >= 0 && ch < 48 ) || ( ch > 57 && ch < 65 ) || ( ch > 90 && ch < 97 ) || ch > 122)
        {                           
                    printf ("\n\n\n\t\t The character is a special symbol.");
        }
        getch ( );


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...