以 C 編寫的 3 位 Osiris 數?


Osiris 數是一個數字,其值等於新增其本身數字的所有排列而形成的所有數字的值的總和。

在此問題中,我們給定了一個 3 位數字 N,我們將檢查數字 N 是否是 Osiris 數。

我們舉一個例子:

Input : N = 132
Output : 132

說明

N 的所有子樣本:13、12、21、23、32、31。

總和 = 13+12+21+23+32+31 = 132

為此,我們有一個公式來檢查給定的數字是否是 Osiris 數。

舉例

 即時演示

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

輸出

132 is an Osiris number

更新於:2019 年 10 月 4 日

109 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.