Duck Number
C Program To Check Duck Numbers
A Duck number is a positive number which has zeroes present in it.Example: 120, 1024, 102030 are all Duck numbers.
Note : A Numbers with only leading 0s is not considered as Duck Number.
Example:
Numbers Like 007 or 001 are Not Considered as Duck Numbers.
To check if a number is a Duck Number or not in C
you can use the following algorithm:
- Read the input number.
- Initialize a variable count to 0.
- While num is not equal to 0, perform the following steps:
- Get the last digit of the num by using the modulo operator (%).
- if last digit = 0 then increase count by 1
- Divide the num by 10 to remove the last digit.
- If count = '0' the number is a Duck Number.
- If count not = '0' the number is Not a Duck Number.
Note that this implementation assumes that the input number is a positive integer. You may need to add additional checks for negative numbers or other cases depending on your requirements.
Here is an example implementation in CSource Code
//C Program To Check Duck Numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int num , Rd , count=0;
printf("Enter a Number To Check : ");
scanf("%d",&num);
while( num!=0 )
{
Rd = num % 10 ;
if( Rd==0 )
count++;
num = num / 10 ;
}
if( count>=1 )
printf("It is a Duck Number . ");
else
printf("It is Not a Duck Number . ");
getch();
}
Output
Sample Input :
Enter a Number To Check : 1024
Sample Output:
It is a Duck Number
Sample Input :
Enter a Number To Check : 123
Sample Output:
It is Not a Duck Number
Looping Related Programs
- C Program to Check Perfect Number or Not
- C Program to Check Prime Number or Not
- C Program to Check Twin Prime Number or Not
- C Program to Check Niven Or Harshad Number or Not
- C Program to Check Spy Number or Not
- C Program to Check Palindrome Number or Not
- C Program to Check Neon Number or Not
- C Program to Check Armstrong Number or Not
- C Program to Check Strong (Krishnamurthy)Number or Not
- C Program to Check Happy Number or Not
- C Program to Check Automorphic Number or Not