C Program
#include <stdio.h>
int main() {
long num;
printf("Enter a number: ");
scanf("%ld", &num);
long temp = num;
int flag = 0;
while (temp > 0) {
if (temp % 10 == 0) { flag = 1; break; }
temp /= 10;
}
if (flag && num % 10 != num)
printf("%ld is a Duck Number", num);
else
printf("%ld is Not a Duck Number", num);
return 0;
}C Output
Input: 5071 Output: 5071 is a Duck Number
C++ Program
#include <iostream>
using namespace std;
int main() {
long num;
cout << "Enter a number: ";
cin >> num;
long temp = num;
bool duck = false;
while (temp > 0) {
if (temp % 10 == 0) { duck = true; break; }
temp /= 10;
}
if (duck && num % 10 != num)
cout << num << " is a Duck Number";
else
cout << num << " is Not a Duck Number";
}C++ Output
Input: 9023 Output: 9023 is a Duck Number
JAVA Program
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
long num = sc.nextLong();
long temp = num;
boolean duck = false;
while (temp > 0) {
if (temp % 10 == 0) { duck = true; break; }
temp /= 10;
}
if (duck && num % 10 != num)
System.out.println(num + " is a Duck Number");
else
System.out.println(num + " is Not a Duck Number");
}
}JAVA Output
Input: 1065 Output: 1065 is a Duck Number
Python Program
num = int(input("Enter a number: "))
temp = num
duck = False
while temp > 0:
if temp % 10 == 0:
duck = True
break
temp //= 10
if duck and num % 10 != num:
print(f"{num} is a Duck Number")
else:
print(f"{num} is Not a Duck Number")Python Output
Input: 704 Output: 704 is a Duck Number
In-Depth Learning – Entire Concept in Paragraphs

Social Plugin