WAP to input number and check that number is disarium number or not. if input : 135, 135=1 + 3*3* +5*5*5.
Answers
Answer:
A Disarium number is a number defined by the following process:
Sum of its digits powered with their respective position is equal to the original number.
For example 175 is a Disarium number:
As 11+32+53 = 135
Some other DISARIUM are 89, 175, 518 etc.
A number will be called Disarium if the sum of its digits powered with their respective position is equal with the number itself. Sample Input: 135.
•Answer:-
package Programmer;
import java.util.*;
public class Disarium
{
public static void main (String ar [])
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int N1=n,s=0,c=0;
while(n!=0)
{
c++;
n/=10;
}
n=N1;
while(n!=0)
{
s+=(int)(Math.pow((n%10),c));
c--;
n/=10;
}
if(s==N1)
System.out.println("Disarium");
else
System.out.println("Not Disarium");
}
}
•Variable Description:-
- n:- to accept input from the user
- N1:- to make copy of 'n'
- c:- to count no. of digits
- s:- to calculate sum