C++ Basic Programming Examples

C++ Program to Display the First 10 Lucus Numbers

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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X