- Full Information About Artificial Intelligence | What is AI?
- Most Common Important 70+ Shortcut Keyboard Keys
- Stars Square Pattern
- Fascinating Number or Not in C and CPP
- Implement queue using linked list c program
- Calculate the GCD | Euclidean algorithm | c and cpp programming language
- Linear search in c | Algorithm of Linear search | c programming
- A C program for checking whether a given line is a comment
- C program to convert decimal to binary without array
- Voting program in C language using switch case
- C program to check eligible for vote
- Insertion and deletion in double linked list in c program
- File read in C | File Handling | How to read File
- C program to replace vowels with special characters
- Call by Reference in C programming language
- Function call by value in c programming language
- Program to print a message without using semicolon in c programming
- User login system in c programming language
- How to make swastik in c and cpp programming language
- Print numbers from 1 to 100 using while loop c and cpp program
- Simple Macro Substitution(#define) in c and cpp programming language
- Insertion and Deletion of all operation at singly Linked list in c programming langauge
- Write a program to count the digit in a number
- Program to calculate the power of given numbers by user in c and cpp
- Sum of digit calculate program
- Write a program to reverse a number
- Floyd Triangle | Programs | Algorithm
- Program to check whether number is Disarium Number
- Sunny Number in programming
- Happy Number | with Example and Programs
- Display Name of the month by accepting digit of the month | c programming
- Spy Number | c programming
- 9 basic program in cpp programming language
- Automorphic number | c programming language
- C programming restaurant menu code lapmos
- Neon Number c programming language
- Strong Number in C programming What is Strong Number
- Leap Year | Leap year program in c
- Pascal Triangle C programming
- Check Palindrome Number in c
- Print Fibonacci Series in c
- Swap two number without using third variable c programming langauge
- Swap two number c programming
- Largest Number c programming language
- Prime number program in c
- What is the mean by Software Engineering?
- Creating an Instagram Login Page Clone with HTML, CSS, and JS: Step-by-Step Guide

A **spy number** is a number whose sum is equal to the product of its digits. For Example: 2141 is a spy number, because the sum of its digits is 2 + 1 + 4 + 1 = 8 and product of its digits is 2 * 1 * 4 * 1 = 8 is equal to sum.

```
// Spy number c program
#include<stdio.h>
int main(){
int n;
int sum = 0, product = 1, last_digit;
printf("Enter the Number : ");
scanf("%d", &n);
int temp = n;
while( n > 0 ){
last_digit = n % 10;
sum = sum + last_digit;
product = product * last_digit;
n = n / 10;
}
if(sum == product){
printf("%d is a Spy Number", temp);
}
else{
printf("%d is not a Spy Number", temp);
}
return 0;
}
```

In this program we have checked the spy number whether the given number is a spy number or not. Now let's talk about how this program is working. In this we first declare a variable whose job is to do the input given by the user, create some more variables which have their own different function like sum variable stores the sum of each digit of the given number and so on. The product variable stores the product. The last_digit variable stores the last digits of the number, after entering the number we created a variable called temp which would store the copy of the given number in this variable whose we can use it later. Then a while loop is started whose termination condition is (n > 0) as long as this condition is true then the statement inside the loop will continue to execute as soon as the condition is false then the loop terminates will go.

Now we talk about the statement written inside the loop, first we will find the last digit inside the loop, as soon as we have calculated the last digit, we will calculate the sum with the help of this statement (sum = sum + last_digit), and product and we (product = product * last_digit) and later we will remove that last digit (n = n / 10).

As soon as the loop is finished then we will compare both sum and product if sum and produce are equal then we will print that given number is spy number and if both are not equal then we will print that given number is not spy number.

- CREATE n, last_digit
- SET temp, sum = 0, product = 1
- Take input(n)
- REPEATE step 5, step 6, step 7, step 8 while ( n > 0)
- last_digit = n % 10
- sum = sum + last_digit
- n = n / 10

[END OF LOOP] - if sum == product PRINT “SPY NUMBER” otherwise
- PRINT “Not SPY Number”
- EXIT

🖤 0

Buy me coffee ☕

## Comments

Oops!