Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CountZeros.cpp #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions C++/CountZeros.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
// Count Zeros

#include <iostream>
#include<iostream>
using namespace std;
int main() {

int countZeros(int n)
{
int zeros = 0;
if (n / 10 == 0)
{
if (n == 0)
{
return 1;
}
else
{
return 0;
}
}
int ans = countZeros(n / 10);
if (n % 10 == 0)
{
ans++;
int n, count = 0;

cout << "Enter a number: "; cin >> n;

while (n != 0) { // loop until the last digit is zero.
if (n % 10 == 0) count++; // increment the counter when we find a zero.
n /= 10; // remove the last digit from our number.
}
return ans;
}

int main()
{
int n;
cin >> n;
cout << countZeros(n) << endl;
}
cout << "The number of zeros in your entered number is: " << count << endl;

return 0;
}