[555 views]

A positive non-zero number is said to be a duck number if it contains zero in it. For example: 450,1089, 78092, 205, etc.

Let us consider the number 1087:

1087 is a duck number as it contains zero in the second position.

Let us consider the number 00245:

00245 is not a duck number as it has two leading zeros, which has no meaning.

In this article, we will learn about the algorithm and flowchart to check whether a given number is duck number or not, followed by a short explanation.

In this problem, we need to check whether a given number is a duck number or not. To do so, we need to check whether the number contains zero or not, keeping in mind that any leading zeros will not be considered.

The algorithm starts off by taking the number to be checked as user input, say ‘n’. We then initialize a flag as false. This will be used to do the final checking. We start a loop that runs until n is not equal to zero. In each iteration of this loop, we extract the last digit of the number by doing: n % 10 and check whether that digit is equal to zero or not. If a zero is found, the flag is set to true and we come out of the loop. When the loop completes its execution, if the flag is true, we display “duck number”, else, there were no zeros in the number, we display “Not a duck number”.

Note: Here ‘%’ is the modulus operator which returns the remainder value after division.

- Algorithm to perform Binary to Decimal Conversion
- Algorithm and Flowchart to check whether a given number is Niven number or not
- Algorithm and flowchart to check whether a given year is a leap year or not
- Algorithm and Flowchart to check whether a string is Palindrome or not
- Algorithm and Flowchart for N Queen Problem with Simple Explanation

- Algorithm and Flowchart to find if a Number is Even or Odd
- Algorithm and Flowchart to find whether a number is Prime Number or Not
- Algorithm and Flowchart for Armstrong Number
- Algorithm for Finding Factorial of a Number
- Algorithm and Flowchart to Calculate Fibonacci series up to n
- How to round a number to nearest integer using python
- Can we have DB table without a primary key?
- Why does everyone hate Java?
- How much JavaScript to learn for Web Development
- How to store password like sensitive information in application