Dremendo Tag Line

Input a number and check if it is a duck number or not using a function in C++

Function - Question 5

In this question, we will see how to input a number and check if it is a duck number or not in C++ programming using a function. To know more about function click on the function lesson.

Q5) Write a program in C++ to input a number and check if it is a duck number or not using a function. The function should return 1 if the numbers is a duck number else return 0.

A duck number is a number which has zero present in it.

Example: 3210, 7056, 35070, etc.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int ducknumber(int num)
{
    int d;
    while(num>0)
    {
        d=num%10;
        if(d==0)
        {
            return 1;
        }
        num=num/10;
    }
    return 0;
}

int main()
{
    int n;
    cout<<"Enter a number ";
    cin>>n;
    if(ducknumber(n)==1)
    {
        cout<<"Duck Number";
    }
    else
    {
        cout<<"Not Duck Number";
    }
    return 0;
}

Output

Enter a number 73062
Duck Number
video-poster