WAP to accept a number and check whether the number is DUCK No. or not.
Answers
The following codes have been written using Python.
n = input("Enter a number: ")
print()
if '0' in n and '0' != n[0]:
print(n, "is a duck number.")
else:
print(n, "is not a duck number. ")
A Duck Number is a number that has a zero (0) in it and does not start with one. 405, 8070, 960, 50, 306, ... etc, are Duck Numbers. 024, 07, 034, ... etc are not Duck Numbers.
Once the data is entered, we check if the character '0' is present in the string [number was input in the form of a string to make it easier for checking and traversing] or not, using an if-else clause.
Answer:
//Java program to check if a number is a duck number or not.
import java.util.*;
public class Program
{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int d=0,flag=0,N1=n;
while(n>0)
{
d=n%10;
if(d==0)
{
flag++;
break;
}
n=n/10;
}
if(flag==0)
System.out.println(N1+" is not a Duck Number");
else
System.out.println(N1+" is a Duck Number");
}
}