Program to print the Fibonacci Half Pyramid Pattern

1 2 

3 5 8 

13 21 34 55 

89 144 233 377 610 


Problem statement:- Program to print the Fibonacci Half Pyramid Pattern.


 Data requirement:-

  Input Data:- row_size

  Output Data:- c

  Additional Data:-out, in or inn(for python), a, b


Program in C

Here is the source code of the C Program to print the Fibonacci Half Pyramid Pattern.


Code:

#include <stdio.h>
int main()
{
    int outina = 0b = 1c = a + b;
    printf("Enter the row size:");
    int row_size;
    scanf("%d", &row_size);
    for (out = 1out <= row_sizeout++)
    {
        for (in = 1in <= outin++)
        {
            printf("%d "c);

            c = a + b;
            a = b;
            b = c;
        }
        printf("\n");
    }
}

Input/Output:
Enter the row size:5
1
1 2
3 5 8
13 21 34 55
89 144 233 377 610


Program in C++

Here is the source code of the C++ Program to print the Fibonacci Half Pyramid Pattern.


Code:

#include <iostream>
using namespace std;
int main()
{
    int outina = 0b = 1c = a + b;
    cout << "Enter the row size :";
    int row_size;
    cin >> row_size;
    for (out = 1out <= row_sizeout++)
    {
        for (in = 1in <= outin++)
        {
            cout << c << " ";
           
            c = a + b;
            a = b;
            b = c;
        }
        cout << "\n";
    }
}

Input/Output:
Enter the row size:4
1
1 2
3 5 8
13 21 34 55

Program in Java

Here is the source code of the Java Program to print the Fibonacci Half Pyramid Pattern.


Code:

import java.util.Scanner;
public class FibonacciHalfPyramidPattern {
    public static void main(String[] args) {
        Scanner cs = new Scanner(System.in);
        System.out.println("Enter the row size:");
        int outina = 0b = 1c = a + b;
        int row_size = cs.nextInt();
        for (out = 1out <= row_sizeout++) {
            for (in = 1in <= outin++) {

                System.out.print(c + " ");

                c = a + b;
                a = b;
                b = c;
            }
            System.out.println();
        }
        cs.close();
    }
}

Input/Output:
Enter the row size:
5
1 2 
3 5 8 
13 21 34 55 
89 144 233 377 610 


Program in Python

Here is the source code of the Python Program to print the Fibonacci Half Pyramid Pattern.


Code:

row_size = int(input("Enter the row size: "))
a = 0
b = 1
c = a+b
for out in range(1, row_size+1):
       for inn in range(1, out+1):
            print(c, end=" ")

            c = a+b
            a = b
            b = c
        print("\r")
Input/Output:
Enter the row size:3
1 2 
3 5 8 


Post a Comment

1 Comments

Please do not Enter any spam link in the comment box