Header Ads Widget

C program to check whether a character is alphabet or not

C program to check whether a character is alphabet or not

Given a character write a program to  check whether it is alphabet or not . For checking this we have three methods .

Method 1:- By using isalpha() function

Method 2:- By using if-else (character>='A' && character<='Z)

Method 3:- By using Ascii values .

Sample input:

5

Sample output:

5 is not a Alphabet

C program to check whether a character is alphabet or not

The objective of the code is to check whether it is a alphabet or not .

Method 1: (By using isalpha() function)

isalpha(character) :- it will take a argument and return True if it is a character otherwise return false . 

Code:-

#include<stdio.h>
int main()
{
char ch;
scanf("%c",&ch);
if(isalpha(ch))
printf("%c is a Alphabet",ch);
else
printf("%c is not a Alphabet",ch);
return 0;
}


Output:

z
z is a Alphabet



Method 2: 

#include<stdio.h>
int main()
{
char ch;
scanf("%c",&ch);
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
printf("%c is a Alphabet",ch);
else
printf("%c is not a Alphabet",ch);
return 0;
}


Output:

z
z is a Alphabet



Method 3:

#include<stdio.h>
int main()
{
char ch;
int a;
scanf("%c",&ch);
// changing character into integer
// (i.e char into ascii)
a=ch;
if((a>=65 && a<=90) || (a>=97 && a<=122))
printf("%c is a Alphabet",ch);
else
printf("%c is not a Alphabet",ch);
return 0;
}


Output:-

z
z is a Alphabet



Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-