isdigit() function in C/C++ with Examples
The isdigit() in C is a function that can be used to check if the passed character is a digit or not. It returns a non-zero value if it’s a digit else it returns 0. For example, it returns a non-zero value for ‘0’ to ‘9’ and zero for others.
The isdigit() function is declared inside ctype.h header file.
C isdigit() Syntax
C isdigit() Parameters
This function takes a single argument in the form of an integer and returns the value of type int.
Note: Even though isdigit() takes an integer as an argument, the character is passed to the function. Internally, the character is converted to its ASCII value for the check.
C isdigit() Return Value
This function returns an integer value on the basis of the argument passed to it
Является ли символ числом
Как проверить,является ли определенный символ в строке числом?
Пользователем вводится строка,после чего нужно посимвольно ее проверить. Если какой-то символ.
Является ли совершенным числом?
Число называется совершенным, если оно равно сумме своих делите- лей (например, 6 = 1 + 2 + 3 = 1.
является ли совершенным числом?
Число называется совершенным, если оно равно сумме своих делителей (например, 6 = 1 + 2 + 3).
Определить, является ли произведение элементов трехзначным числом
Определить, является ли произведение элементов трехзначным числом. одномерный массив
How to check if a character is a digit in C#
Many candidates are rejected or down-leveled in technical interviews due to poor performance in behavioral or cultural fit interviews. Ace your interviews with this free course, where you will practice confidently tackling behavioral interview questions.
Overview
A character can be an alphabet, symbol, etc. In other words, a character can be alphanumeric. In C#, we can use the IsDigit() method to check if a character is numeric or a digit.
The IsDigit() method can be used on a single character or on a string. In the case of a string, we have to specify the index position of the character in the string.
IsDigit() returns true if the character is a decimal digit; otherwise, it returns false .
Syntax
Parameters
Char : The character we want to check.
String : The string that we want to check to see if any character at index position int32 is a digit.
int32 : The index position of the character in a string we want to check.
Code example
In the example below, we create some strings and characters and see if certain characters are decimal digits or not.
C library function — isdigit()
The C library function int isdigit(int c) checks if the passed character is a decimal digit character.
Decimal digits are (numbers) − 0 1 2 3 4 5 6 7 8 9.
Declaration
Following is the declaration for isdigit() function.
Parameters
c − This is the character to be checked.
Return Value
This function returns non-zero value if c is a digit, else it returns 0.
Example
The following example shows the usage of isdigit() function.
Let us compile and run the above program, to produce the following result −