Thursday, October 8, 2009

Determine character input if its Capital,small,decimal or special character

/*Any character is entered through the keyboard ,write a program to determine whether the character entered is a capital letter,a small case letter,a digit or a special symbol

Following is Range of Ascii values for various characters:-

Characters                                           Ascii Values

A-Z                                                        65-90

a-z                                                         97-122

0-9                                                         48-57

Special symbols                                   0-47,58-64,91-96,123-127 */


#1 Solution ( With Value of ASCII characters as integer as input) :-

========================================

#include <stdio.h>
int main(void)
{
int i;
printf("Enter a character to determine its type : ");
scanf("%d",&i);


if ( (i <= 90) && (i >= 65))
printf("\nIts %c whose value is %d ,which belongs to A-Z character type",i,i);
else if ( i <= 122 && i >= 97 )
printf("\nIts %c whose value is %d,which belongs to a-z character type",i,i);
else if ( i <= 57 && i >= 48 )
printf("\nIts %c whose value is %d,which belongs to 0-9 character type",i,i);
else if (( i <= 47 && i >= 0) || ( i <= 64 && i >= 58) || ( i >= 91 && i <= 96) || ( i <= 127 && i >= 123))
printf("\nIts %c whose value is %d,which belongs to specific symbols",i,i);
return 0;
}
 

#2 Solution ( With ASCII Characters as input ) :-

==============================

#include <stdio.h>
int main(void)
{
char i;

printf("Enter a character to determine its type :");
scanf("%c",&i);


if (( i <= 'Z') && (i >= 'A'))
printf("\nIts %c whose value is %d ,which belongs to A-Z character type",i,i);
else if (( i >= 'a') && (i <= 'z' ))
printf("\nIts %c whose value is %d,which belongs to a-z character type",i,i);
else if ( (i >= '0') && (i <= '9'))
printf("\nIts %c whose value is %d,which belongs to 0-9 character type",i,i);
else
printf("\nIts %c whose value is %d,which belongs to *special symbols*",i,i);
return 0;
}


No comments: