You are given an integer N.
Each digit in the number contains a certain number of holes.
๐ข Hole Definition:
- Digits 0, 4, 6, 9 โ have 1 hole
- Digit 8 โ has 2 holes
- All other digits โ have 0 holes
๐ฏ Task
Calculate and print the total number of holes present in all digits of the given number.
๐ฅ Input Format
- A single integer N
๐ค Output Format
- Print a single integer representing the total number of holes
๐ Constraints
- 1โคNโค109
๐งช Example 1
Input:
649578
Output:
5
Explanation:
- 6 โ 1 hole
- 4 โ 1 hole
- 9 โ 1 hole
- 5 โ 0 holes
- 7 โ 0 holes
- 8 โ 2 holes
Total = 1 + 1 + 1 + 0 + 0 + 2 = 5
๐งช Example 2
Input:
630
Output:
2
Explanation:
- 6 โ 1 hole
- 3 โ 0 holes
- 0 โ 1 hole
Total = 2
C Program
#include <stdio.h>
int countHoles(int number) {
int holes = 0;
while (number > 0) {
int digit = number % 10;
if (digit == 0 || digit == 4 || digit == 6 || digit == 9) {
holes += 1;
} else if (digit == 8) {
holes += 2;
}
number /= 10;
}
return holes;
}
int main() {
int number;
scanf("%d", &number); // โ No print message
printf("%d", countHoles(number)); // โ Only output
return 0;
}