Page 256 - CA_Blue( J )_Class9
P. 256
Program 11 Write a program to display if a number is a strong number. (A number is said to be a strong
number, if the sum of the factorial of the digits of the number is same as the original number).
Example: 145 is a strong number, because 1! + 4! + 5! = 1 + 24 + 120 = 145.
(Where ! stands for factorial of the number and the factorial value of a number is the product
of all integers from 1 to that number, example 5! = 1 * 2 * 3 * 4 * 5 = 120)
1 import java.util.*;
2 class Special {
3 public static void main () {
4 Scanner sc= new Scanner (System.in);
5 int n,sum=0,r,f,t,i;
6 System.out.print("Enter a number: ");
7 n=sc.nextInt();
8 t=n;
9 while(t>0)
10 { r= t % 10;
11 f=1;
12 for (i= 1; i<=r;i++)
13 {f=f*i;
14 }
15 sum= sum + f;
16 t=t/10;
17 }
18 if (n == sum)
19 System.out.println(n + " is a special number.");
20 else
21 System.out.println(n + " is not a special number.");
22 }
23 }
You will get the following output:
254 Touchpad Computer Applications-IX

