A Number is a Spy number if the sum of its digits equal to the product of its digits.
Example:
Given Number=123
Sum of digits =1+2+3=6
product of digits=1*2*3=6
Problem statement:- Program to check whether the number is Spy Number or Not.
Data requirement:-
Input Data:- num
Output Data:- String output
Additional Data:- sum, rem, mult
Program in C
Example:
Given Number=123
Sum of digits =1+2+3=6
product of digits=1*2*3=6
Problem statement:- Program to check whether the number is Spy Number or Not.
Data requirement:-
Input Data:- num
Output Data:- String output
Additional Data:- sum, rem, mult
Program in C
Here is the source code of the C Program to check whether the number is Spy Number or Not.
Code:
//spy Number Or Not
#include<stdio.h>
int main()
{
int num,i;
printf("Enter the number:");
scanf("%d",&num);
//Sum of digit
int sum=0,mult=1,rem;
while(num!=0)
{
rem=num%10;
sum+=rem;
mult*=rem;
num/=10;
}
if(sum==mult)
printf("It is a Spy Number.");
else
printf("It is not a Spy Number.");
}
Input/Output:#include<stdio.h>
int main()
{
int num,i;
printf("Enter the number:");
scanf("%d",&num);
//Sum of digit
int sum=0,mult=1,rem;
while(num!=0)
{
rem=num%10;
sum+=rem;
mult*=rem;
num/=10;
}
if(sum==mult)
printf("It is a Spy Number.");
else
printf("It is not a Spy Number.");
}
Enter the number:123
It is a Spy Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Spy Number or Not.
It is a Spy Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Spy Number or Not.
Code:
#include <iostream>
using namespace std;
int main()
{
int num,i;
cout<<"Enter the number:";
cin>>num;
int sum=0,mult=1,rem;
while(num!=0)
{
rem=num%10;
sum+=rem;
mult*=rem;
num/=10;
}
if(sum==mult)
cout<<"It is a spy Number.";
else
cout<<"It is not a spy Number.";
}
Input/Output:using namespace std;
int main()
{
int num,i;
cout<<"Enter the number:";
cin>>num;
int sum=0,mult=1,rem;
while(num!=0)
{
rem=num%10;
sum+=rem;
mult*=rem;
num/=10;
}
if(sum==mult)
cout<<"It is a spy Number.";
else
cout<<"It is not a spy Number.";
}
Enter the number:30
It is not a spy Number.
Program in Java
It is not a spy Number.
Program in Java
Here is the source code of the Java Program to check whether the number is Spy Number or Not.
Code:
import java.util.Scanner;
public class SpyNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int sum=0,mult=1,rem;
while(num!=0)
{
rem=num%10;
sum+=rem;
mult*=rem;
num/=10;
}
if(sum==mult)
System.out.println("It is a Spy Number.");
else
System.out.println("It is not a Spy Number.");
cs.close();
}
}
Input/Output:public class SpyNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int sum=0,mult=1,rem;
while(num!=0)
{
rem=num%10;
sum+=rem;
mult*=rem;
num/=10;
}
if(sum==mult)
System.out.println("It is a Spy Number.");
else
System.out.println("It is not a Spy Number.");
cs.close();
}
}
Enter a number:
22
It is a Spy Number.
22
It is a Spy Number.
Program in Python
Here is the source code of the Python Program to check whether the number is Spy Number or Not.
Code:
num=int(input("Enter a number:"))
sum=0
mult=1
while num!=0:
rem = num % 10
sum += rem
mult *= rem
num //= 10
if sum==mult:
print("It is a spy Number.")
else:
print("It is not a spy Number.")
sum=0
mult=1
while num!=0:
rem = num % 10
sum += rem
mult *= rem
num //= 10
if sum==mult:
print("It is a spy Number.")
else:
print("It is not a spy Number.")
Input/Output:
0 Comments
Please do not Enter any spam link in the comment box