Easy
Given a character, check if it represents an odd digit, an even digit or not a digit at all.
Example
- For symbol = '5', the output should be
characterParity(symbol) = "odd"; - For symbol = '8', the output should be
characterParity(symbol) = "even"; - For symbol = 'q', the output should be
characterParity(symbol) = "not a digit".
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] char symbol
A symbol to check.
Guaranteed constraints:
symbol is guaranteed to be a UTF-8 symbol. -
[output] string
[C] Syntax Tips
// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
char * answer = malloc(strlen(name) + 8);
printf("This prints to the console when you Run Tests");
strcpy(answer, "Hello, ");
strcat(answer, name);
return answer;
}
더보기
Solution
char *characterParity(char symbol)
{
if(!isdigit(symbol))
return "not a digit";
else if((symbol-'0')%2==0)
return "even";
else
return "odd";
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> New Numeral System (0) | 2020.05.24 |
---|---|
<Codesignal> Reflect String (0) | 2020.05.24 |
<Codesignal> Three Split (0) | 2020.05.24 |
<Codesignal> Ada Number (0) | 2020.05.23 |
<Codesignal> Integer to String of Fixed width (0) | 2020.05.08 |