w3resource

C Programming: Check whether a character is digit or not


30. Check Digit Character

Write a program in C to check whether a character is a digit or not.

C Programming: Check whether a character is digit or not


Sample Solution:

C Code:

#include<stdio.h>
#include<ctype.h>

int main() {
    char TestChar; // Variable to store the input character

    // Display a message to prompt the user to input a character
    printf("\n Check whether a character is digit or not :\n");
    printf("----------------------------------------------\n");
    printf(" Input a character : ");

    scanf("%c", &TestChar); // Read a character from user input

    // Check if the input character is a digit using isdigit() function
    if (isdigit(TestChar)) {
        printf(" The entered character is a digit. \n\n"); // Display message if it's a digit
    } else {
        printf(" The entered character is not a digit. \n\n"); // Display message if it's not a digit
    }

    return 0; // Return 0 to indicate successful execution of the program
}

Output:

 Check whether a character is digit or not :
----------------------------------------------
 Input a character : 8
 The entered character is a digit.

Flowchart:

Flowchart: Check whether a character is digit or not


For more Practice: Solve these Related Problems:

  • Write a C program to check if an input character is a digit by comparing its ASCII value without using isdigit().
  • Write a C program to determine if a character is numeric and convert it to its integer equivalent.
  • Write a C program to validate whether a character is a digit and print a corresponding message.
  • Write a C program to test if a character is a digit and count its occurrences in a user-provided string.

Go to:


PREV : Remove Spaces from File Content.
NEXT : Split String by Spaces.

C Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.