Spy number
Spy number is a sum of all digit equal to the Product of all digit.
Example-1:
Input : n = 1124 Output : Spy number Explain : Sum of all digits(1+1+2+4=8) and Product of all digits(1*1*2*4=8). The sum of all digits is equal to the product of all digits. So its "Spy number".
Example-2:
Input : n = 42 Output : Not a spy number Explain : Sum of all digits(4+2=6) and Product of all digits(4*2=8). The sum of all digits is not equal to the product of all digits. So its "Not a Spy number".
Solution
public class Main { public static void main(String [] args) { int n = 132; int sum = 0, product = 1; while(n!=0) { sum = sum + n % 10; product = product * n % 10; n = n/10; } if(sum==product) { System.out.print("Spy number"); } else { System.out.print("Not a Spy number"); } } }
n = 1124 sum = 0 prod = 1 while(n!=0): sum += n % 10 prod *= n % 10 n = n // 10 if(sum==prod): print("Spy number") else: print("Not a spy number")
Output
Spy number