이 튜토리얼에서는 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