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;
}
1 Comment
Problem Statement: Featured Product - Dheeraj Hitech · April 3, 2026 at 11:51 am
[…] product that sells the most on a given day becomes the featured product for the next […]