C Program#152 – To check character is Digit or Not using Conditional Operator.

Program to Check Character is Digit or Not (Conditional Operator):

Program Logic : Check Character (Digit/Number or Not)

  • Digits 0-9 have ASCII Codes 48 to 57 in ASCII Table.
  • Declare a single character variable, take input of single character using %c in scanf() function.
  • Define test-condition in Conditional Operator, for checking digit/number using ASCII Codes 48-57.
  • Conditional Expression – (ch>=48 && ch<=57) , checks for Digits 0 to 9..
  • (ch>=48 && ch<=57), logical expression checks character is a Digit or Not.
  • If conditions results True than it’s a Digit (0 to 9) otherwise Not.
  • Still not understood ? See the proper working example in action below.

Full Well Commented, Self-Explanatory Example Program of the same given below.

Below Here are Four (4) different Outputs of the program.

Output of the Program (Run 1 – Input: DIGIT):

Output of the Program (Run 2 – Input – ALPHABET):

Output of the Program (Run 3 – Input – NON-ALPHANUMERIC):

Output of the Program (Run 4 – Input – NONE-Enter Key):