Computer Science, asked by NairaRajpal, 1 year ago

Write a program to print Fibonacci Series.

Answers

Answered by AJAYMAHICH
10
#include <stdio.h>
int main()
{
 int i, n, num1 = 0, num2 = 1, num3;

 printf("Enter the number of terms: ");
 scanf("%d", &n);

 printf("Fibonacci Series: ");

 for (i = 1; i <= n; ++i)
 {
 printf("%d, ", t1);
 num3 = num1 + num2;
 num1 = num2;
 num2 = num3;
 }
 return 0;
}
Answered by siddhartharao77
18

Fibonacci series: In this, the current term is the sum of two previous terms.

Here is a small program for Fibonacci series:

import java.util.*;

class Hello

{

public static void main(String[] args)

{

int num1 = 0, num2 = 1, num3, num4;

Scanner demo = new Scanner(System.in);

System.out.print("Enter the number: ");

num4 = demo.nextInt();

System.out.print(num1+ " " +num2);

for(int i = 2;i < num4; i++)

{

num3 = num1 + num2;

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

num1 = num2;

num2 = num3;

}

}

}


Output:

Enter the number: 5

0

1

1

2

3.

Attachments:

siddhartharao77: thank you to both :-)
Similar questions