## Description

A Number is a **disarium number** if the sum of the digits powered with their respective positions is equal to the number itself.

For Example:

89 is a **Disarium Number**

89:> 8^{1 }+ 9^{2} = 8 + 81 = 89

## Write a c program to check whether a given number Disarium Number.

```
#include <stdio.h>
#include<math.h>
int main()
{
int n, temp;
int sum = 0, count = 0;
printf("Enter a number : ");
scanf("%d", &n);
// First Count the digits of the number
temp = n;
while(temp!=0){
temp = temp/10;
count = count + 1;
}
temp = n;
while(count!=0){
int last_digit = temp%10;
temp = temp/10;
sum = sum + pow(last_digit,count);
count = count - 1;
}
if(sum == n){
printf("%d is a Disarium Number", n);
}else{
printf("%d is not a Disarium Number", n);
}
return 0;
}
```

## Write a c++ program to check whether a given number Disarium Number.

```
// 175 = 1^1 + 7^2 + 5^3 = 1 + 49 + 125 = 50 + 125 = 175
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int n, temp;
int sum = 0, count = 0;
cout<<"Enter a number : ";
cin>>n;
// First Count the digits of the number
temp = n;
while(temp!=0){
temp = temp/10;
count = count + 1;
}
temp = n;
while(count!=0){
int last_digit = temp%10;
temp = temp/10;
sum = sum + pow(last_digit,count);
count = count - 1;
}
if(sum == n){
cout<<n<<" is a Disarium Number";
}else{
cout<<n<<" is not a Disarium Number";
}
return 0;
```

Output:

Enter a Number: 175

175 is a Disarium Number.

## Algorithm to check the number is Disarium number.

- Calculate the length count digits of given number
- SET temp = n
- Use a while loop to check whether the number is not equal to 0.
- Divide the number by 10 and increment the count by 1.

- SET temp = n again
- Calculate the answer of the given number
- Use a while loop to check whether the count is not equal to 0.
- Define and Assign last_digit
- Calculate the last digit
- Remove the last digit by temp = temp / 10.
- Calculate the sum = sum + pow(last_digit, count).
- Decrement the count by 1.

- \Check the given number and sum
- If the given number and sum is equal then PRINT “GIVEN NUMBER IS DISARIUM” otherwise go to step 2
- PRINT “GIVEN NUMBER IS NOT DISARIUM”;

- Exit.

## Recommended Posts

## Floyd Triangle | Programs | Algorithm

A Floyd Triangle is right angled triangle consisting of consecutive natural numbers starting with one and then going down through the rows.

## Sum of digit calculate program

We can get the sum of the digit by adding every digits of the given number forgetting the place of value of the digit.

## Program to Calculate the power of given numbers by user in c and cpp

In this program, we will take two inputs from the users, one will be the base and the another one is exponent.

## Write a program to count the digit in a Number

To count the digits of a given number, divided that number by 10 until that number is greater than 0.

## Insertion and Deletion of all operation at Singly Linked List in C Programming Language

Insertion and Deletion in Singly(singular) linked list in C programming langauge Data Structure. How to Implement insertion and deletion.