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: Find Duck Numbers between 1 to 500

C++ Numbers: Exercise-27 with Solution

Write a program in C++ to find Duck Numbers between 1 to 500.

Pictorial Presentation:

C++ Exercises: Find Duck Numbers between 1 to 500

Sample Solution:

C++ Code :

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

int main()
{
    int dno,dkno,r,flg;
	flg=0;
 cout << "\n\n Find Duck Numbers between 1 to 500: \n";
 cout << " ----------------------------------------\n";
 cout << " The Duck numbers are: "<<endl;
for(dkno=1;dkno<=500;dkno++)
	{
	dno=dkno;
	flg=0;
    while(dno>0)
        {
            if(dno % 10==0)
            {
            flg=1;
            break;

            }
			dno/=10;
        }
            if(dkno>0 && flg==1)
            {
            cout << dkno<<" ";
            }
	}
	cout<<endl;
}

Sample Output:

 Find Duck Numbers between 1 to 500:                                   
 ----------------------------------------                              
 The Duck numbers are:                                                 
10 20 30 40 50 60 70 80 90 100 101 102 103 104 105 106 107 108 109 110 
120 130 140 150 160 170 180 190 200 201 202 203 204 205 206 207 208 209
 210 220 230 240 250 260 270 280 290 300 301 302 303 304 305 306 307 30
8 309 310 320 330 340 350 360 370 380 390 400 401 402 403 404 405 406 4
07 408 409 410 420 430 440 450 460 470 480 490 500

Flowchart:

Flowchart: Find Duck Numbers between 1 to 500

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C++ to check whether a number is a Duck Number or not.
Next: Write a program in C++ to check two numbers are Amicable numbers or not.

What is the difficulty level of this exercise?