Check whether character is digit or not in C
This code checks whether given character is digit or not by using respective ascii values of characters.
/* Aim: TO Check Whether The Character is a Digit (0-9) or not */
#include<stdio.h>
int main()
{
char a;
printf("\n Enter your character:");
scanf("%c",&a);
if((a>=48) && (a<=57))
{
printf("\n The Character %c is digit \n \n",a);
}
else
{
printf("\n The Character %c is not digit \n \n ",a);
}
return 0;
}
Output:
Enter your character:9
The Character 9 is digit
Enter your character:F
The Character F is not digit