C Program to Check Whether a Character is Digit or not


Program


#include<stdio.h>
#include<conio.h>

int main()
{
	 char ch;
	 clrscr();
	 printf("Enter chracter: ");
	 scanf("%c", &ch);
	
	 if(ch>='0' && ch<='9')
	 {
	  	printf("%c is DIGIT.", ch);
	 }
	 else
	 {
	  	printf("%c is NOT DIGIT.", ch);
	 }
	
	 getch();
	 return(0);
}

Output of above program :

Run 1:
----------
Enter any character: 9 ↲
9 is DIGIT.

Run 2:
----------
Enter any character: G ↲
G is NOT DIGIT.

Run 3:
----------
Enter any character: % ↲
% is NOT DIGIT.

Run 4:
----------
Enter any character: 5 ↲
5 is DIGIT.

Note: ↲ indicates ENTER is pressed.