Disarium Number.

Program to check whether a given number is Disarium or not.


A number will be called Disarium if sum of its digits powered with their respective postion is equal to the original number.

eg. 135 is a Disarium number because 135 = (1)+(3*3)+(5*5*5) similarly 89, 175, 518 etc are Disarium number








SOURCE CODE

import java.io.*;
public class Disarium
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter a Number  :");
        int a=Integer.parseInt(br.readLine());
        int re,c=a,j=0;
        while(c>0)
        {
            c=c/10;
            j++;
        }
        int rem,d=0,n=a;
        while(n>0)
        {
            rem=n%10;
            d=d+(int)Math.pow(rem,j);
            n=n/10;
            j--;
        }
        if(d==a)
        System.out.println("Yes,It is a Disarium Number");
        else
        System.out.println("No, It is not a Disarium Number");
    }
}



Click here to Download

OUTPUT





If you have any question then leave a comment below I will do my best to answer that question.


Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.