3 位奥西里斯数 C 程序?
在此我们将看到奥西里斯数字。奥西里斯数字是这种数字,它们等于其自身数字的子样本的排列之和。假设数字为 132。那么如果我们计算 {12 + 21 + 13 + 31 + 23 + 32},这同样也是 132。因此,该数是奥西里斯数字。我们必须检查给定的数字是否是奥西里斯数字。
方法很简单。如果我们分析这些数字,每个数字出现两次,因此它们在个位数和十位数上。因此,我们可以通过用 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP