C++ program to print Fibonacci triangle – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Tue, 29 Sep 2020 07:18:34 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg C++ program to print Fibonacci triangle – Programmerbay https://programmerbay.com 32 32 C++ program to print Fibonacci triangle https://programmerbay.com/c-program-to-print-fibonacci-triangle/ https://programmerbay.com/c-program-to-print-fibonacci-triangle/#respond Wed, 05 Feb 2020 17:39:52 +0000 https://www.programmerbay.com/?p=2473 The program prints Fibonacci triangle. A Fibonacci series is a series where each number is the sum of  two immediate preceding numbers. For example , 0,1,1,2,3,5 …. and so on.

C++ program to print Fibonacci triangle

Program:

#include <iostream>

using namespace std;

int main ()
{
  int num1 = 0, num2 = 1, totalElements, nextNum;
  totalElements = 4;
  num1 = 0;
  num2 = 1;
  	  cout << "***************** Fibonacci triangle *************" << endl;
  for (int i = 0; i <= totalElements; i++)
    {
      for (int j = 0; j < i; j++)
  {
    nextNum = num1 + num2;
    cout << " " << num2;
    num1 = num2;
    num2 = nextNum;
  } 
  cout << endl;
    } 
    return 0;
}

Output:

***************** Fibonacci triangle *************                                                                     

                                                                                                                       

 1                                                                                                                     

 1 2                                                                                                                   

 3 5 8                                                                                                                 

 13 21 34 55

]]>
https://programmerbay.com/c-program-to-print-fibonacci-triangle/feed/ 0