Affluent Savvy
Photo by Matheus Bertelli Pexels Logo Photo: Matheus Bertelli

What is Duck number?

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.

What color is best for protection?
What color is best for protection?

Black Black. Black is the color of protection, banishing, grounding, and safety. Jul 3, 2018

Read More »
What are the signs of an insecure person?
What are the signs of an insecure person?

Signs of Insecurity An overriding feeling of inadequacy. Low self-esteem, self-confidence, and self-worth. Like they are unable or ill-equipped to...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

Check Whether a number is Duck Number or not

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.

Implementation:

C++

#include using namespace std; bool check_duck(string num) { int i = 0, n = num.length(); while (i < n && num[i] == '0' ) i++; while (i < n) { if (num[i] == '0' ) return true ; i++; } return false ; } int main( void ) { string num = "1023" ; if (check_duck(num)) cout << "It is a duck number

" ; else cout << "It is not a duck number

" ; return 0; } Java

import java.io.*; class GFG { static boolean check_duck(String num) { int i = 0 , n = num.length(); while (i < n && num.charAt(i) == '0' ) i++; while (i < n) { if (num.charAt(i) == '0' ) return true ; i++; } return false ; } 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 def check_duck(num) : n = len (num) i = 0 while (i < n and num[i] = = '0' ) : i = i + 1 while (i < n) : if (num[i] = = "0" ) : return True i = i + 1 return False num1 = "1023" if (check_duck(num1)) : print "It is a duck number" else : print "It is not a duck number" C# using System; class GFG { static bool check_duck( String num) { int i = 0, n = num.Length; while (i < n && num[i] == '0' ) i++; while (i < n) { if (num[i] == '0' ) return true ; i++; } return false ; } public static void Main() { String num1 = "1023" ; if ( check_duck(num1)) Console.Write( "It is a " + "duck number" ); else Console.Write( "It is not " + "a duck number" ); } } Javascript

Output It is a duck number

Time Complexity: O(n) where n is length of string.

Auxiliary Space: O(1)

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.

Is $100000 a year rich?
Is $100000 a year rich?

In most parts of the country, a $100,000 salary is considered good; maybe even very, very good. It can be more than enough for an individual or...

Read More »
What was Egypt called in biblical times?
What was Egypt called in biblical times?

Mizraim Biblical Egypt (Hebrew: מִצְרַיִם; Mīṣrāyīm), or Mizraim, is a theological term used by historians and scholars to differentiate between...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

What is a karmic master number?
What is a karmic master number?

Numbers 11, 22, and 33 are considered the only Master Numbers in numerology since these numbers are made up of 1, 2, and 3, respectively. These...

Read More »
How long do spiders live in a house?
How long do spiders live in a house?

1-2 years The average house spider lifespan can be anything from 1-2 years, which is quite a long time for a spider to be in your home. As well as...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
What cleans arteries fast?
What cleans arteries fast?

Here are some of the best foods that unclog arteries to eat in order to prevent or clean clogged arteries. Berries. Strawberries, blueberries,...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
Can I spray cinnamon oil on my plants?
Can I spray cinnamon oil on my plants?

The great thing about Cinnamon Oil is that it is non toxic and safe for your plants, children and pets. Of course you must dilute it because...

Read More »