icse-promo

Question

Write a program to input a number and print whether the number is a special number or not. (A number is said to be a special number, if the sum of the factorial of the digits of the number is same as the original number).

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class program6
{
    public static void main(String args[])
    {
	int num=0, temp=0, digit=0, sum = 0 , fact=0,i=0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number to be checked.");
        num = sc.nextInt();
        temp = num;
        
        while(temp!=0)
        {
            digit = temp%10;
	        fact=1;
            for(i = 1; i<=digit; i++)
            {
                fact=fact*i;
            }
            sum = sum + fact;
            temp = temp/10;
        }
        if(sum==num)
        {
            System.out.println(num+" is a Special Number.");
        }
        else
        {
            System.out.println(num+" is not a Special Number.");
        }
    }
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *