Computer Science, asked by itsRida, 3 months ago

Write a program to accept a number and check and display whether it is a spy number or not.
(A number is a spy number if the sum of its digits equals the product of its digits.)
Example: Consider the number 1124
Sum of digits=1+1+2+4= 8
Product of the digits = 1x1x2x4 = 8

Answers

Answered by Equestriadash
8

The following cσdes have been written using Python.

n = int(input("Enter a number: "))

print()

s = 0

for i in str(n):

   s = s + int(i)

print("The sum of the digits is: ", s)

p = 1

for i in str(n):

   p = p*int(i)

print("The product of the digit is: ", p)

print()

if s == p:

   print(n, "is a Spy Number.")

else:

   print(n, "is not a Spy Number.")

Answered by BrainlyProgrammer
4

Answer:

This is done in JAVA

//Java Program to check if a number is a spy number or not

package Programmer;

import java.util.Scanner;

public class Spy {

public static void main(String[] args) {

Scanner sc=new Scanner (System.in);

System.out.println("Enter a number");

int n=sc.nextInt();

int s=0,p=1;

for(;n!=0;n/=10){

s+=n%10;

p*=n%10;

}

System.out.println((s==p)?"Spy Number":"Not a Spy Number");

}

}

__

Variable Description:-

  1. s:- to Calculate sum of the digits
  2. p:- to calculate product of the digits
  3. n:- to accept the number from the user

__

• Output Attached

Attachments:
Similar questions