C Program
#include <stdio.h> #include <math.h> int main() { int n, temp, count = 0, sum = 0; scanf("%d", &n); temp = n; // Count digits int t = n; while (t > 0) { count++; t /= 10; } // Calculate sum of digits powered by their positions t = n; while (t > 0) { int digit = t % 10; sum += pow(digit, count); count--; t /= 10; } if (sum == n) printf("%d is a Disarium Number\n", n); else printf("%d is not a Disarium Number\n", n); return 0; }
C Output
Input: 135 Output: 135 is a Disarium Number
C++ Program
#include <iostream> #include <cmath> using namespace std; int main() { int n; cin >> n; int temp = n, count = 0, sum = 0; // Count digits int t = n; while (t > 0) { count++; t /= 10; } // Sum of powered digits t = n; while (t > 0) { int digit = t % 10; sum += pow(digit, count); count--; t /= 10; } if (sum == n) cout << n << " is a Disarium Number\n"; else cout << n << " is not a Disarium Number\n"; }
C++ Output
Input: 89 Output: 89 is a Disarium Number
JAVA Program
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), temp = n, count = 0, sum = 0; // Count digits int t = n; while (t > 0) { count++; t /= 10; } // Sum of powered digits t = n; while (t > 0) { int digit = t % 10; sum += Math.pow(digit, count); count--; t /= 10; } if (sum == n) System.out.println(n + " is a Disarium Number"); else System.out.println(n + " is not a Disarium Number"); } }
JAVA Output
Input: 175 Output: 175 is a Disarium Number
Python Program
n = int(input()) num_str = str(n) length = len(num_str) sum_val = 0 for i, digit in enumerate(num_str, start=1): sum_val += int(digit) ** i if sum_val == n: print(f"{n} is a Disarium Number") else: print(f"{n} is not a Disarium Number")
Python Output
Input: 89 Output: 89 is a Disarium Number
In-Depth Learning – Entire Concept in Paragraphs
Example
Social Plugin