Check Whether a number is Duck Number or not - GeeksforGeeks

13 Apr, 2021
A Duck number is a positive number which has zeroes present in it, For example 3210, 8050896, 70709 are all Duck numbers. Please note that a numbers with only leading 0s is not considered as Duck Number. For example, numbers like 035 or 0012 are not considered as Duck Numbers. A number like 01203 is considered as Duck because there is a non-leading 0 present in it.
Examples :
Input : 707069 Output : It is a duck number. Explanation: 707069 does not contains zeros at the beginning.
Input : 02364 Output : It is not a duck number. Explanation: in 02364 there is a zero at the beginning of the number.
C++
Java
Python
C#
Javascript
// C++ Program to check whether// a number is Duck Number or not.#include <iostream>using namespace std; // Function to check whether// given number is duck number or not.bool check_duck(string num){    // Ignore leading 0s    int i = 0, n = num.length();    while (i < n && num[i] == '0')        i++;     // Check remaining digits    while (i < n) {        if (num[i] == '0')            return true;        i++;    }     return false;} // Driver Methodint main(void){    string num = "1023";    if (check_duck(num))        cout << "It is a duck number\n";    else        cout << "It is not a duck number\n";     return 0;}
// Java Program to check whether a// number is Duck Number or not. import java.io.*;class GFG {     // Function to check whether    // the given number is duck number or not.    static boolean check_duck(String num)    {        // Ignore leading 0s        int i = 0, n = num.length();        while (i < n && num.charAt(i) == '0')            i++;         // Check remaining digits        while (i < n) {            if (num.charAt(i) == '0')                return true;            i++;        }         return false;    }     // Driver Method    public static void main(String args[]) throws IOException    {        String num = "1023";        if (check_duck(num))            System.out.println("It is a duck number");        else            System.out.println("It is not a duck number");    }}
# Python program to check whether a number is Duck Number or not. # Function to check whether# the given number is duck number or not.def check_duck(num) :     # Length of the number(number of digits)    n = len(num)        # Ignore leading 0s    i = 0    while (i < n and num[i] == '0') :        i = i + 1     # Check remaining digits    while (i < n) :        if (num[i] == "0") :            return True        i = i + 1     return False      # Driver Methodnum1 = "1023"if(check_duck(num1)) :    print "It is a duck number"else :    print "It is not a duck number" # Write Python3 code here
// C# Program to check whether a// number is Duck Number or not.using System; class GFG {         // Function to check whether    // the given number is duck    // number or not.    static bool check_duck( String num)    {                 // Ignore leading 0s        int i = 0, n = num.Length;        while (i < n && num[i] == '0')            i++;         // Check remaining digits        while (i < n) {            if (num[i] == '0')                return true;            i++;        }         return false;    }          // Driver Method    public static void Main()    {                 String num1 = "1023";                 // checking number1        if( check_duck(num1))            Console.Write("It is a "                      + "duck number");        else            Console.Write("It is not "                    + "a duck number");    }} // This code is contributed by// nitin mittal.
<script> // Javascript program to check whether// a number is Duck Number or not. // Function to check whether// given number is duck number or not.function check_duck(num){         // Ignore leading 0s    let i = 0, n = num.length;    while (i < n && num[i] == '0')        i++;     // Check remaining digits    while (i < n)    {        if (num[i] == '0')            return true;                     i++;    }    return false;} // Driver codelet num = "1023"; if (check_duck(num))    document.write("It is a duck number");else    document.write("It is not a duck number");     // This code is contributed by rishavmahato348 </script>
Output : 
It is a duck number.
This article is contributed by Nikita Tiwari. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
nitin mittal
Sam007
keshvi2298
rishavmahato348
Mathematical
School Programming
Strings
Strings
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program to find sum of elements in a given array
Euclidean algorithms (Basic and Extended)
The Knight's tour problem | Backtracking-1
Find minimum number of coins that make a given value
Algorithm to solve Rubik's Cube
Python Dictionary
Arrays in C/C++
Inheritance in C++
Reverse a string in Java
Interfaces in Java