﻿ C++ Exercises: Show Duck Numbers between 1 to 500 - w3resource

# 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: