-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignment2ex10.c
70 lines (56 loc) · 1.52 KB
/
Assignment2ex10.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* You are designing a poster which prints out numbers with a unique
style applied to each of them. The styling is based on the number of
closed paths or holes present in a giver number. The number of holes
that each of the digits from 0 to 9 have are equal to the number of closed
paths in the digit. Their values are:
• 1, 2, 3, 5 and 7 = 0 holes.
• 0, 4, 6, and 9 = 1 hole.
• 8 = 2 holes.*/
#include<stdio.h>
int holes(int number);
int main() {
int number;
scanf("%d" , &number);
printf("%d" , holes(number));
}
int holes(int number ) {
int holes = 0 ;
while(number > 0 ) {
int singleDigit = number%10;
switch (singleDigit)
{
case 1 :
holes = holes + 0;
break;
case 2 :
holes = holes + 0;
break;
case 3 :
holes = holes + 0;
break;
case 5 :
holes = holes + 0;
break;
case 7 :
holes = holes + 0; //mmmmmmmmm
break;
case 0 :
holes = holes + 1;
break;
case 4 :
holes = holes + 1;
break;
case 6 :
holes = holes + 1;
break;
case 9 :
holes = holes + 1;
break;
case 8 :
holes = holes + 2;
break;
}
number = number/10;
}
return holes ;
}