Computer Science, asked by sapnarsapnar, 3 months ago

write a program to accept a number and check whether it is a spy number or not(using a while loop) (A number is spy if sum of its digits is equal to product of its digits)​

Answers

Answered by adithyaa24032006
6

Answer:

Write a program to accept a number and check and display whether it is a spy number or not. (A number is spy if the sum of its digits equals the product of its digits.)

Example: consider the number 1124,

Sum of the digits = l + l+ 2 + 4 = 8

Product of the digits = 1×1 x2x4 = 8

SOLUTION

class Spy {

public static void main(int n) {

int sum = 0;

int multiple = 1;

int a;

int p = n;

// a stores each digit extracted and p creates a backup of input.

while(n ! = 0) {

a = n % 10; ,

sum = sum + a;

multiple = multiple * a;

n = n/10;

}

System.out.println(“The sum of ” +p +” is ”+sum);

System.out.println(“The product of “+p +” is ” + multiple);

if(sum = = multiple) {

System.out.println(“Aha, ” + “It is a Spy Number Where Sum = Product”);

}

else {

System.out.println(” It is NOT a Spy Number Where Sum ft Product”);

}

}

}

Explanation:

please like me or put stars and brainlist answer please

Answered by Anonymous
2

Answer:

hello,

its using python...

Explanation:

#program to accept a number and check whether it is a spy number or not

n=int(input("enter the number"))

prod=1

sum=0

while n>0:

   r=n%10

   sum=sum+r

   prod=prod*r

   n=n//10

if sum==prod:

   print("its a spy number")

else:

   print("its not a spy number")

hope it helps you

please mark brainliest

@ItzSnowySecret07

Similar questions