# Write A Program To Check Entered Number Is A Spy Number Or Not Through C Program

In this post I am going to discuss a program called, Entered Number A Spy Number Or Not.

## What is Spy Number?

When you enter a natural number like 1124 then sum up its digit is equal to product of all the digits. Like,

``````//Example:
Suppose n=1124
Product of digits on prod=(1 * 1 * 2 * 4) = 8
Sum of digits on sum=(1 + 1 + 2 + 4) = 8
Here, sum==prod both product and sum are equal.
Output: Spy Number

Input : 1412
Explanation :
sum = (1 + 4 + 1 + 2) = 8
product = (1 * 4 * 1 * 2) = 8
since, sum == product == 8
Output : Spy Number

Input : 132
Explanation :
sum = (1 + 3 + 2) = 6
product = (1 * 3 * 2) = 6
since, sum == product == 6
Output : Spy Number``````

## C program to check number is a spy number or not(Using For Loop):

```#include <stdio.h>

int main()
{
int n,s=0,p=1,d;
printf("Enter any no ");
scanf("%d",&n);
for(;n>0;)
{
d=n%10;
s=s+d;
p=p*d;
n=n/10;
}
printf("Sum of digits = %d Product of digits = %d\n",s,p);
if(s==p)
printf("Number is a Spy Number");
else
printf("Number is not a Spy Number");
return 0;
}```
##### Case-1:
``````Output:
Enter any no 253
Sum of digits = 10 Product of digits = 30
Number is not a Spy Number``````
##### Case-2:
``````Output:
Enter any no 123
Sum of digits = 6 Product of digits = 6
Number is a Spy Number``````

## C program to check number is a spy number or not(Using While Loop):

```#include <stdio.h>

int main()
{
int n,s=0,p=1,d;
printf("Enter any no ");
scanf("%d",&n);
while(n>0)
{
d=n%10;
s=s+d;
p=p*d;
n=n/10;
}
printf("Sum of digits = %d Product of digits = %d\n",s,p);
if(s==p)
printf("Number is a Spy Number");
else
printf("Number is not a Spy Number");
return 0;
}```
##### Case-1:
``````Enter any no 321
Sum of digits = 6 Product of digits = 6
Number is a Spy Number``````
##### Case-2:
``````Enter any no 365
Sum of digits = 14 Product of digits = 90
Number is not a Spy Number``````

## C program to check number is a spy number or notUsing Function Without Passing Arguments:

```#include <stdio.h>
void check()
{
int n,s=0,p=1,d;
printf("Enter any no ");
scanf("%d",&n);
while(n>0)
{
d=n%10;
s=s+d;
p=p*d;
n=n/10;
}
printf("Sum of digits = %d Product of digits = %d\n",s,p);
if(s==p)
printf("Number is a Spy Number");
else
printf("Number is not a Spy Number");
}

int main()
{
check();
return 0;
}```
##### Case-1:
``````Enter any no 312
Sum of digits = 6 Product of digits = 6
Number is a Spy Number``````
##### Case-2:
``````Enter any no 145
Sum of digits = 10 Product of digits = 20
Number is not a Spy Number``````

## C program to check number is a spy number or notUsing Function Passing Argument

```#include <stdio.h>
void check(int n)
{
int s=0,p=1,d;
while(n>0)
{
d=n%10;
s=s+d;
p=p*d;
n=n/10;
}
printf("Sum of digits = %d Product of digits = %d\n",s,p);
if(s==p)
printf("Number is a Spy Number");
else
printf("Number is not a Spy Number");
}

int main()
{
int n;
printf("Enter any no ");
scanf("%d",&n);

check(n);
return 0;
}```
##### Case-1:
``````Enter any no 965
Sum of digits = 20 Product of digits = 270
Number is not a Spy Number``````
##### Case-1:
``````Enter any no 231
Sum of digits = 6 Product of digits = 6
Number is a Spy Number``````