#include<stdio.h>
#include<conio.h>
#include<conio.h>
void main()
{
char ch;
clrscr(); //to clear the screen
printf(“Enter any character:”);
scanf(“%c”,&ch);
if((ch>=’A’&&ch<=’Z’)||(ch>=’a’&&ch<=’z’))
printf(“nYou have entered an alphabet”);
else
if(ch>=’0’&&ch<=’9′)
printf(“nYou have entered a digit”);
else
printf(“nYou have entered a special character”);
getch(); //to stop the screen
}
Nice code.
/* smaller code 🙂 */
#include
int main()
{
char a;
printf("Please input a character: ");
scanf("%c", &a);
(a >= 'a' && a <= 'z' || a>='A' && a<='Z' || a>='0'&& a<= '9' ? printf("character is not special") : printf("character is special") );
getch();/* not to use if making prog in command line directly using devc++ */
}
Yes Nitin, we can also use your code. It is little bit smaller. Thanks for your suggestion.
Sir can you tel me how to write this program using switch case… Plz send me that code to my mail id.. kasturisatishkumar@gmail.com
if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
what will happen if we don't add parentheses for each expression on either sides of the logical or operator ?!
pls help 🙂
We are adding parenthesis to ensure any kind of confusion, otherwise the expression will be executed according to operator precedence and this will cause undesired results. This also make the expression easy to understand. 🙂
Thanks (Y)
Please write algorithm for this program
What if we want to input 10 characters and then check
How to write a program to check whether the given input is alphabet, number or special character using (switch case)? Please teach me 🙁