C Program to check input character is number, symbol or alphabet

Program to check input keyboard is an alphabet or not in C language

 

 

In this article, you’ll learn to check whether an input is entered by the user from the keyboard is alphabet, vowel or number in C program with example and explain in detail.

As we know that:

  • Alphabet = A to Z or a to z
  • Number = 0 to 9
  • Symbol = ~, @, #, $, %, ^, &, *, (, ), _/_, +, =, >, <, /, ?, etc all character are symbol for this program.

Step by step explanation:

  • First, we create three variables, they are lowercase, uppercase, and alpha
  • Print “ Enter an alphabet “ on the screen
  • User give an input which is alphabet then
  • We Store input alphabet which is entered by the user in the alpha variable with the help of predefined function scanf then
  • We check input character is alphabet or not
  • If alphabet then print on screen alphabet
  • Otherwise, print on the screen, not an alphabet

 

Q: write a program in C language to check, input is given by user from the keyboard is alphabet or not

Solution:

#include <stdio.h>

#include <conio.h>

int main()

{

int lowerCase, upperCase;

char alpha;

printf(“Enter an alphabet: “);

scanf(“%c”,&alpha);

if((alpha>=’a’ && alpha<=’z’) || (alpha>=’A’&& alpha<=’z’))

printf(“%c is an alphabet”,alpha);

else

printf(“\n%c is not an alphabet”,alpha);

return 0;

}

The output of this program:

Enter an alphabet: $

 

$ is not an alphabet

 

Note: if the user enters any number except alphabet then print on screen “ is a consonant” because this programming only checking for alphabet or not.

Q: write a program in C language to check whether an input is an alphabet or not using do-while, an input is given by user from the keyboard.

Solution:

#include <stdio.h>

#include <conio.h>

int main()

{

int lowerCase, upperCase;

char alpha;

do{

printf(“Enter an alphabet: “);

scanf(“%c”,&alpha);

}

while (!(alpha));

if((alpha>=’a’ && alpha<=’z’) || (alpha>=’A’&& alpha<=’z’))

printf(“%c is an alphabet”,alpha);

else

printf(“\n%c is not an alphabet”,alpha);

return 0;

}

 

The output of this program:

Enter an alphabet: $

 

$ is not an alphabet

Program to check input keyboard is number, symbol or alphabet in C language

 

Q: write a program in C language to check whether an input is an alphabet, number or symbol, an input is given by user from the keyboard.

Solution:

#include <stdio.h>

#include <conio.h>

int main()

{

int lowerCase, upperCase;

char alpha;

printf(“Enter an alphabet: “);

scanf(“%c”,&alpha);

if((alpha>=’a’ && alpha<=’z’) || (alpha>=’A’&& alpha<=’z’))

printf(“%c is an alphabet”,alpha);

else if(alpha>=’0′ && alpha<=’9′)

printf(“\n%c is a number”,alpha);

else

printf(“\n%c is a symbol “,alpha);

return 0;

}

 

The output of this program:

 

Enter an alphabet: %

 

% is a symbol

 

Q: write a program in C language to check whether an input is an alphabet, number or symbol using do-while, an input is given by user from the keyboard.

Solution:

#include <stdio.h>

#include <conio.h>

int main()

{

int lowerCase, upperCase;

char alpha;

do{

printf(“Enter an alphabet: “);

scanf(“%c”,&alpha);

}

while (!(alpha));

if((alpha>=’a’ && alpha<=’z’) || (alpha>=’A’&& alpha<=’z’))

printf(“%c is an alphabet”,alpha);

else if(alpha>=’0′ && alpha<=’9′)

printf(“\n%c is a number”,alpha);

else

printf(“\n%c is a symbol “,alpha);

return 0;

}

 

The output of this program:

 

Enter an alphabet: 99

 

9 is a number

 

You may also learn the following programming:

Leave a Reply

Your email address will not be published. Required fields are marked *

itetrade.com