Codesignal
<Codesignal> evenDigitsOnly
우현짱짱
2020. 4. 5. 17:00
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