Computer Science, asked by monikak4374, 5 days ago

Write a program to input a number and print whether the number is Special number or not

[Hint: A number is said to be special, if the sum of the factorial of each digit of the number is same as the original number.

Ex: 145, 1!+4!+5! = 1+24+120 = 145
which output screenshot

Answers

Answered by anitanama784
5

Answer:

import java.util.Scanner;

public class KboatSpecialNum

{

public static int fact(int y) {

int f = 1;

for (int i = 1; i <= y; i++) {

f *= i;

}

return f;

}

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter number: ");

int num = in.nextInt();

int t = num;

int sum = 0;

while (t != 0) {

int d = t % 10;

sum += fact(d);

t /= 10;

}

if (sum == num)

System.out.println(num + " is a special number");

else

System.out.println

Similar questions