In this program, we will check whether the ASCII value of input character(C)is in between the ASCII value of '0' and '9' decimal digit character(including '0' and '9').
In other words, If '0' <= C <= '9' is true, then C is a decimal digit character.
In other words, If '0' <= C <= '9' is true, then C is a decimal digit character.
Required Knowledge
C program to check for decimal digit characters using conditional operator
#include <stdio.h> int main() { char c; int isDigit; printf("Enter a Character\n"); scanf("%c", &c); /* Check, If input character is digit */ isDigit = ((c >= '0') && (c <= '9'))? 1 : 0; if(isDigit == 1) printf("%c is Digit\n", c); else printf("%c is Not a Digit\n", c); return 0; }Output
Enter a Character 7 7 is Digit
Enter a Character A A is Not a Digit
Related Topics