Home  >  Article  >  Backend Development  >  C program for Osiris numbers with 3 digits?

C program for Osiris numbers with 3 digits?

WBOY
WBOYforward
2023-08-26 08:05:15715browse

C program for Osiris numbers with 3 digits?

Here we will see the Osiris. The number of Osiris is a number that is equal to the sum of permutations of subsamples of its own number. Suppose this number is 132, then if we calculate {12 21 13 31 23 32}, this is also 132. So this number is the number of Osiris. We have to check if the given number is the number of Osiris.

The method is very simple. If we analyze these numbers, each number appears twice, so they are in the ones and tens places. So we can check that by multiplying them by 11.

Algorithm

isOsirisNumber(n) -

Begin
   a := last digit
   b := second digit
   c := first digit
   digit_sum := a + b + c
   if n = (22 * digit_sum), then
      return true
   end if
   return false
End

Example

#include
using namespace std;
bool isOsirisNumber(int n) {
   int a = n % 10;
   int b = (n / 10) % 10;
   int c = n / 100;
   int sum = a + b + c;
   if (n == (22 * sum)) {
      return true;
   }
   return false;
}
int main() {
   int n = 132;
   if (isOsirisNumber(n))
      cout << "This is Osiris number";
   else
      cout << "This is Not Osiris number";
}

Output

This is Osiris number

The above is the detailed content of C program for Osiris numbers with 3 digits?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete