The Program in C++ Program to Display the First 10 Lucus Numbers is given below:
#include <iostream>
#include <cmath>
using namespace std;
long long lucas(int n) {
if (n == 0) return 2;
if (n == 1) return 1;
return lucas(n - 1) + lucas(n - 2);
}
int main() {
cout << "Hello Codeauri Family, the first 10 Lucas numbers are:" << endl;
for (int i = 0; i < 10; i++) {
cout << lucas(i) << " ";
}
cout << endl;
return 0;
}
Output:
Hello Codeauri Family, the first 10 Lucas numbers are:
2 1 3 4 7 11 18 29 47 76
Pro-Tips💡
The program defines a function called “lucas” that takes an integer as input and returns the corresponding Lucas number.
The function calculates the Lucas number using a recursive approach, where each number is calculated as the sum of the two previous numbers.
The main function then calls the “lucas” function 10 times, each time with a different value for the input integer,
and prints the resulting Lucas numbers.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.