w3resource
C Programming Exercises

C Programming: Check whether a character is digit or not

C String: Exercise-30 with Solution

Write a program in C to check whether a character is 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;
	printf("\n Check whether a character is digit or not :\n");  
    printf("----------------------------------------------\n");      
    printf(" Input a character : ");
    scanf( "%c", &TestChar );
	if( isdigit(TestChar) )
		printf( " The entered character is a digit. \n\n" );
	else
		printf( " The entered character is not a digit. \n\n" );
	return 0;
}

Sample 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

C Programming Code Editor:

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

Previous: Write a program in C to read a file and remove the spaces between two words of its content.
Next: Write a program in C to split string by space into words.

What is the difficulty level of this exercise?