Check whether a number has consecutive 0’s in C++

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this C++ Program, we will check if the given number has consecutive 0’s .

C++ Program to check whether a number has a consecutive 0’s

#include<bits/stdc++.h>
using namespace std;
int toK(int N, int K)
{
    int w = 1;
    int s = 0;
    while (N != 0)
     {
        int r = N % K;
        N = N/K;
        s = r * w + s;
        w *= 10;
     }
    return s;
  }
  
bool check(int N)
{
    bool fl = false;
    while (N != 0)
    {
  
        int r = N % 10;
        N = N/10;
        if (fl == true and r == 0)
            return false;
        if (r > 0)
            {
            fl = false;
            continue;
            }
        fl = true;
  
    }
    return true;
          
}
void result(int N, int K)
{
    int z = toK(N, K);
    if (check(z))
       cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
}
  
int main()
{
int Number = 10;
int K = 5;
result(Number, K);
  
}

Output: Yes

Leave a Comment

Your email address will not be published. Required fields are marked *