在本教程中,我们将讨论一个查找N lccanobif数的程序。
为此,我们将提供一个整数。我们的任务是在该位置找到lccanobif号。它们与斐波那契数字相似,不同之处在于我们在反转两个数字后将前两个数字相加。
#include <bits/stdc++.h> using namespace std; //反转数字 int reverse_digits(int num){ int rev_num = 0; while (num > 0) { rev_num = rev_num * 10 + num % 10; num = num / 10; } return rev_num; } //打印第一个N lccanobif数字 void icanobifNumbers(int N){ int first = 0, second = 1; if (N == 1) cout << first; else if (N == 2) cout << first << " " << second; else { cout << first << " " << second << " "; for (int i = 3; i <= N; i++) { int x = reverse_digits(first); int y = reverse_digits(second); cout << x + y << " "; int temp = second; second = x + y; first = temp; } } } int main(){ int N = 12; icanobifNumbers(N); return 0; }
输出结果
0 1 1 2 3 5 8 13 39 124 514 836