FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp/F20RecursionAssignment/CountZeros.cpp at main · roydevashish/cpp · GitHub
roydevashish
/
cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp
/
F20RecursionAssignment
/
CountZeros.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (43 loc) · 913 Bytes
Breadcrumbs
cpp
/
F20RecursionAssignment
/
CountZeros.cpp
Copy path
File metadata and controls
57 lines (43 loc) · 913 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Title: Count Zeros
Problem statement
Given an integer N, count and return the number of zeros that are present in the given integer
using recursion.
Detailed explanation ( Input/output format, Notes, Images )
Input Format :
Integer N
Output Format :
Number of zeros in N
Constraints :
0 <= N <= 10^9
Sample Input 1 :
0
Sample Output 1 :
1
Sample Input 2 :
00010204
Sample Output 2 :
2
Explanation for Sample Output 2 :
Even though "00010204" has 5 zeros, the output would still be 2 because when you convert it to an
integer, it becomes 10204.
Sample Input 3 :
708000
Sample Output 3 :
4
*/
#
include
<
iostream
>
using
namespace
std
;
int
CountZeros
(
int
n) {
if
(n ==
0
) {
return
0
;
}
int
small_output =
CountZeros
(n/
10
);
int
output = n %
10
==
0
?
1
+ small_output : small_output;
return
output;
}
int
main
() {
int
n;
cin >> n;
cout <<
CountZeros
(n) << endl;
}
Back
|
FazBrowse Home
|
New Git URL