This program checks if a given number is a strong number or not. A strong number is a number whose sum of factorials of each digit is equal to the original number.
Note that this program assumes that the input is a positive integer. If the input is not a positive integer, the program behavior is undefined.
import java.util.Scanner; public class strong { //Write a program to check the given number is Strong number or not. public static void main(String args[]) { int num,originalNum,rem,fact,i,sum=0; Scanner in = new Scanner(System.in); System.out.println("Enter a number : "); num=in.nextInt(); originalNum=num; while (num>0)//145>0 14>0 1>0 { rem=num%10; //System.out.println("Reminder : "+rem); fact=1; for(i=1;i<=rem;i++){ fact*=i;//fact=fact*i } //System.out.println("fact : "+fact); sum+=fact; num=num/10; } if (sum == originalNum) { System.out.println(originalNum + " is STRONG NUMBER"); } else { System.out.println(originalNum + " is not a STRONG NUMBER"); } } }
Enter a number : 145 145 is STRONG NUMBER
Enter a number : 234 234 is not a STRONG NUMBERTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions