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 a 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
}
Sample Output:
Check whether a character is digit or not : ---------------------------------------------- Input a character : 8 The entered character is a digit.
Flowchart :
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?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming-exercises/string/c-string-exercise-30.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics