A Number is a Disarium number if the sum of the digits powered with their respective positions is equal to the number itself.
Example:
Given Number=135
135⇒1¹+3²+5³=1+9+125=135
so, 135 is Disarium Number.
Given Number=120
120⇒1¹+2²+0³=1+4+0=5
so, 120 is not a Disarium Number.
Problem statement:- Program to check whether the number is Disarium Number or Not.
Data requirement:-
Input Data:- num
Output Data:- String output
Additional Data:- num1, c, sum, rem
Program in C
Here is the source code of the C Program to check whether the number is Disarium Number or Not.
Code:
///Disarium Number Or Not
#include<stdio.h>
#include<math.h>
int main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
int num1=num,c=0;
while(num1!=0)
{
num1/=10;
c++;
}
num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
sum+=pow(rem,c);
num1/=10;
c--;
}
if(sum==num)
printf("It is a Disarium Number.");
else
printf("It is not a Disarium Number.");
}
#include<stdio.h>
#include<math.h>
int main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
int num1=num,c=0;
while(num1!=0)
{
num1/=10;
c++;
}
num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
sum+=pow(rem,c);
num1/=10;
c--;
}
if(sum==num)
printf("It is a Disarium Number.");
else
printf("It is not a Disarium Number.");
}
Input/Output:
Enter the number:135
It is a Disarium Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Disarium Number or Not.
It is a Disarium Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Disarium Number or Not.
Code:
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int num,i;
cout<<"Enter the number:";
cin>>num;
int num1=num,c=0;
while(num1!=0)
{
num1/=10;
c++;
}
num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
sum+=pow(rem,c);
num1/=10;
c--;
}
if(sum==num)
cout<<"It is a Disarium Number.";
else
cout<<"It is not a Disarium Number.";
}
#include<cmath>
using namespace std;
int main()
{
int num,i;
cout<<"Enter the number:";
cin>>num;
int num1=num,c=0;
while(num1!=0)
{
num1/=10;
c++;
}
num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
sum+=pow(rem,c);
num1/=10;
c--;
}
if(sum==num)
cout<<"It is a Disarium Number.";
else
cout<<"It is not a Disarium Number.";
}
Input/Output:
Enter the number:120
It is not a Disarium Number.
Program in Java
It is not a Disarium Number.
Program in Java
Here is the source code of the Java Program to check whether the number is Disarium Number or Not.
Code:
import java.util.Scanner;
public class DisariumNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int num1=num,c=0;
while(num1!=0)
{
num1/=10;
c++;
}
num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
sum+=Math.pow(rem,c);
num1/=10;
c--;
}
if(sum==num)
System.out.println("It is a Disarium Number.");
else
System.out.println("It is not a Disarium Number.");
cs.close();
}
public class DisariumNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int num1=num,c=0;
while(num1!=0)
{
num1/=10;
c++;
}
num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
sum+=Math.pow(rem,c);
num1/=10;
c--;
}
if(sum==num)
System.out.println("It is a Disarium Number.");
else
System.out.println("It is not a Disarium Number.");
cs.close();
}
Input/Output:
Enter a number:
175
It is a Disarium Number.
175
It is a Disarium Number.
Program in Python
Here is the source code of the Program to check whether the number is Disarium Number or Not.
Code:
import math
num=int(input("Enter a number:"))
num1 = num
c=0
while num1!=0:
num1 //= 10
c+=1
num1=num
sum=0
while num1!=0:
rem = num1 % 10
sum += math.pow(rem, c)
num1 //= 10
c-=1
if sum==num:
print("It is a Disarium Number.")
else:
print("It is Not a Disarium Number.")
num=int(input("Enter a number:"))
num1 = num
c=0
while num1!=0:
num1 //= 10
c+=1
num1=num
sum=0
while num1!=0:
rem = num1 % 10
sum += math.pow(rem, c)
num1 //= 10
c-=1
if sum==num:
print("It is a Disarium Number.")
else:
print("It is Not a Disarium Number.")
Input/Output:
Enter a number:150
It is Not a Disarium Number.
It is Not a Disarium Number.
Most Recommend Questions:-
More Questions:-
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box