Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Check whether a number is a Duck Number or not

C++ Numbers: Exercise-26 with Solution

Write a program in C++ to check whether a number is a Duck Number or not.

Pictorial Presentation:

C++ Exercises: Check whether a number is a Duck Number or not

Sample Solution:

C++ Code :

# include <bits/stdc++.h>
using namespace std;

int main()
{
    int dno,dkno,r,flg;
	flg=0;
 cout << "\n\n Check whether a number is a Duck Number or not: \n";
 cout << " ----------------------------------------------------\n";
 cout << " Input a number: ";
 cin >> dkno;
 dno=dkno;
    while(dkno>0)
        {
            if(dkno % 10 == 0)
            {
            flg=1;
            break;
            }
			dkno/=10;
        }
            if(dno>0 && flg==1)
            {
            cout << " The given number is a Duck Number."<<endl;
            }
            else
            {
            cout << " The given number is not a Duck Number."<<endl;
            }
}

Sample Output:

Check whether a number is a Duck Number or not:                       
 ----------------------------------------------------                  
 Input a number: 30                                                    
 The given number is a Duck Number. 

Flowchart:

Flowchart: Check whether a number is a Duck Number or not

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C++ to find the Authomorphic numbers between 1 to 1000.
Next: Write a program in C++ to find Duck Numbers between 1 to 500.

What is the difficulty level of this exercise?