Showing posts with label fibonacci. Show all posts
Showing posts with label fibonacci. Show all posts

Fibonacci Sequence in C++

This program generates the Fibonacci sequence up to a given number of terms.

#include <iostream>

int main() {

    int n, t1 = 0, t2 = 1, nextTerm = 0;

    std::cout << "Enter the number of terms: ";

    std::cin >> n;


    std::cout << "Fibonacci Series: " << t1 << ", " << t2 << ", ";

    nextTerm = t1 + t2;


    for (int i = 3; i <= n; ++i) {

        std::cout << nextTerm << ", ";

        t1 = t2;

        t2 = nextTerm;

        nextTerm = t1 + t2;

    }

    std::cout << "\b\b " << std::endl;  // Remove the last comma and space

    return 0;

}


Fibonacci Sequence in C

This program generates the Fibonacci sequence up to a given number of terms.

#include <stdio.h>

 int main() {
    int n, t1 = 0, t2 = 1, nextTerm = 0;
    printf("Enter the number of terms: ");
    scanf("%d", &n);
 
    printf("Fibonacci Series: %d, %d, ", t1, t2);
    nextTerm = t1 + t2;
 
    for (int i = 3; i <= n; ++i) {
        printf("%d, ", nextTerm);
        t1 = t2;
        t2 = nextTerm;
        nextTerm = t1 + t2;
    }
    printf("\b\b \n");  // Remove the last comma and space
    return 0;
}

Fibonacci Sequence in Python

This program generates the Fibonacci sequence up to a given number of terms.

 
n = int(input("Enter the number of terms: "))
t1, t2 = 0, 1
print("Fibonacci Series:", t1, t2, end=", ")
for _ in range(3, n + 1):
    nextTerm = t1 + t2
    print(nextTerm, end=", ")
    t1, t2 = t2, nextTerm

MS Excel Logical Functions

Logical functions in Excel are powerful tools that help you make decisions based on conditions. Whether you're comparing values or testi...

Post Count

Loading...