Easy
Check if all digits of the given integer are even.
Example
- For n = 248622, the output should be
evenDigitsOnly(n) = true; - For n = 642386, the output should be
evenDigitsOnly(n) = false.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] integer n
Guaranteed constraints:
1 ≤ n ≤ 10^9. -
[output] boolean
- true if all digits of n are even, false otherwise.
[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
bool evenDigitsOnly(int n)
{
while(n>0)
{
if(n%2==1)
return false;
n/=10;
}
return true;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> alphabeticShift (0) | 2020.04.05 |
---|---|
<Codesignal> variableName (0) | 2020.04.05 |
<Codesignal> Array Replace (0) | 2020.04.05 |
<Codesignal> Minesweeper (0) | 2020.04.05 |
<Codesignal> Box Blur (0) | 2020.04.05 |