Solution with out using functions(Using For Loop)
Solution with out using functions(Using While Loop)
Solution using functions without passing arguments
Solution using functions and by passing arguments
Spy Number :
If the Sum of the digits and Product of the digits same then the number is said to be a Spy number.
example:
n=123
Sum of digits=6
Product of digits=6
Number is a Spy number
n=234
Sum of digits=9
Product of digits=24
Number is a not Spy number
C program to check number is a spy number or not(Using For Loop)
Solution : Without using function
Program/Source Code
#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; }
Output:
case 1:
Enter any no 253
Sum of digits = 10 Product of digits = 30
Number is not a Spy Number
case 2:
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)
Solution : Without using function
Program/Source Code
#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; }
Output:
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 not
Solution : Using function Without Passing Arguments
Program/Source Code
#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; }
Output:
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 not
Solution : Using function Passing Arguments
Program/Source Code
#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; }
Output:
case 1:
Enter any no 965
Sum of digits = 20 Product of digits = 270
Number is not a Spy Number
case 2:
Enter any no 231
Sum of digits = 6 Product of digits = 6
Number is a Spy Number
Previous:
Next: |
Tutorials | Technical Questions | Interview Questions |
---|---|---|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions C Programs C++ Programs |