![]() |
VOOZH | about |
Given number N, the task is to check whether it is divisible by 5. Print "Yes" if N is divisible by 5; otherwise, print "No".
Examples:
Input: N = 155
Output: Yes
Explanation: If we divide 155 by 5, we get the remainder as 0, therefore 155 is divisible by 5.Input: N = 17
Output: No
Explanation: If we divide 17 by 5, we get the remainder by 2, therefore 17 is divisible by 5.
If observed carefully, all the multiples of 5 have either 0 or 5 as its last digit hence to check the divisibility, below two cases can be formed:
- if (Last digit of N == 0 or last digit of N == 5): N is divisible by 5
- Else N is not divisible by 5.
Note: To get the last Digit we can use the formula last Digit = N%10
Step-by-step approach:
Below is the implementation of the above approach:
17 is not divisible by 5
Time Complexity: O(1)
Auxiliary Space: O(1)
When you divide one integer by another, the remainder can be 0 (indicating exact divisibility) or a non-zero value (indicating that there is a remainder). If the remainder is 0, it means that the dividend is divisible by the divisor.
Step-by-step approach:
N % 5 equals 0, then N is divisible by 5.N is not divisible by 5.Below is the implementation of the approach:
155 is divisible by 5
Time Complexity: O(1)
Auxiliary Space: O(1)