Last Updated on 25 Dec 2021 by Satya Prakash Singh Rathour
2 mins read
Spy Number (Sum and Products of Digits are same):-
A number is said to be a Spy number if the sum of all the digits is equal to the product of all digits.
#include <iostream> using namespace std;
bool check_SPY_Number(int num) { int digit, sum = 0, product = 1; while (num > 0) { digit = num % 10; sum += digit; product *= digit; num = num / 10; }
if (sum == product) return true; else return false; }
int main() { int num = 12345; if (check_SPY_Number(num)) cout << "The number is " << "a Spy number" << "\n"; else cout << "The number is " << "NOT a spy number" << "\n"; return 0; }