3-digit Osiris number in C?


Osiris Number is a number whose value is equal to the sum of values of all number formed by adding all the permutations of its own digits.

In this problem, we are given a 3-Digit number N, and we will check weather the number N is an Osiris number.

Let’s take an example,

Input : N = 132
Output : 132

Explanation

All sub-samples of N : 13 , 12, 21, 23 ,32 31.

Sum = 13+12+21+23+32+31 = 132

To do this, we have a formula to check whether the given number is Osiris number or not.

Example

 Live Demo

#include <stdio.h>
int main() {
   int n = 132;
   int a = n % 10;
   int b = (n / 10) % 10;
   int c = n / 100;
   int digit_sum = a + b + c;
   if (n == (2 * (digit_sum)*11)) {
      printf("%d is an Osiris number",n);
   }
   else
      printf("%d is not an Osiris number",n);
   return 0;
}

Output

132 is an Osiris number

Updated on: 04-Oct-2019

101 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements