Home > Backend Development > C++ > body text

C program for Osiris numbers with 3 digits?

WBOY
Release: 2023-08-26 08:05:15
forward
755 people have browsed it

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
Copy after login

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";
}
Copy after login

Output

This is Osiris number
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template