用 C++ 查詢前 N 個 Iccanobif 數的程式
在本教程中,我們將討論一個查詢 N 個 lccanobif 數字的程式。
為此,我們將提供一個整數。我們的任務是找到該位置的 lccanobif 數字。它們與斐波那契數類似,但不同的是,我們在反轉數字後將前兩個數字相加。
示例
#include <bits/stdc++.h>
using namespace std;
//reversing the digits of a number
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;
}
//printing the first N lccanobif numbers
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP