patternprogram_58 softethics

Pattern 58 (Fibonacci Pyramid)

C

// Fibonacci piramid

#include<stdio.h>

#include<math.h>
int main()
{
  int firstNum=0,secondNum=1,result=0;
  int i,j;
  int n=5; //size

  for(i=1; i<=n; i++)
  {
    for(j=1; j<=i; j++)
    {
      firstNum=secondNum;
      secondNum=result;
      printf("%d",result);
      result=firstNum+secondNum;
    }
    firstNum=0;
    secondNum=1;
    result=0;
    printf("\n");
  }
  return 0;
}

C++

 // Fibonacci piramid
 
 #include<iostream.h>
 
 #include<math.h>
 int main()
 {
 int firstNum=0,secondNum=1,result=0;
 int n=5; //size ,increase it to create series
 
 for(int i=1;i<=n;i++)
 {
 for(int j=1;j<=i;j++)
 {
 firstNum=secondNum;
 secondNum=result;
 cout<<result<<" ";
 result=firstNum+secondNum;
 }
 firstNum=0;
 secondNum=1;
 result=0;
 cout<<endl;
 }
 return 0;
 }

Java

     class PatternProg
     {
     public static void main(String args[])
     {
 int firstNum=0,secondNum=1,result=0;
 int n=5; //size ,increase it to create series
  
 for(int i=1;i<=n;i++)
 {
 for(int j=1;j<=i;j++)
 {
 firstNum=secondNum;
 secondNum=result;
 System.out.print(result+" ");
 result=firstNum+secondNum;
 }
 firstNum=0;
 secondNum=1;
 result=0;
 System.out.println();
 }
     } //end of main
 }  //end of class

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int firstNum = 0, secondNum = 1, result = 0;
    int n = 5; //size ,increase it to create series

    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j <= i; j++)
      {
        firstNum = secondNum;
        secondNum = result;
        Console.Write(result + " ");
        result = firstNum + secondNum;
      }
      firstNum = 0;
      secondNum = 1;
      result = 0;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  } //end of main
} //end of class

Python

n = 10  # size
n1 = 0
n2 = 1
r = 0

for x in range(0, n):
    for y in range(0, x + 1):
        n1 = n2
        n2 = r
        print(str(r) + " ", end="")
        r = n1 + n2
    n1 = 0
    n2 = 1
    r = 0
    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments