ホームページ  >  記事  >  バックエンド開発  >  3桁のオシリス数のCプログラム?

3桁のオシリス数のCプログラム?

WBOY
WBOY転載
2023-08-26 08:05:15696ブラウズ

3桁のオシリス数のCプログラム?

ここでオシリスを見てみましょう。オシリスの数は、オシリス自身の数のサブサンプルの順列の合計に等しい数です。この数値が 132 だとすると、{12 21 13 31 23 32} を計算すると、これも 132 になります。したがって、この数字はオシリスの数です。与えられた数がオシリスの数であるかどうかを確認する必要があります。

方法は非常に簡単です。これらの数値を分析すると、それぞれの数値が 2 回出現するため、1 と 10 の位になります。したがって、それらを 11 で乗算することで確認できます。

アルゴリズム

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

#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";
}

出力

This is Osiris number

以上が3桁のオシリス数のCプログラム?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。