C++ Exercises: Find Duck Numbers between 1 to 500
C++ Numbers: Exercise-27 with Solution
Write a C++ program to find Duck Numbers between 1 and 500.
Pictorial Presentation:

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:

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?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join