xxxxxxxxxx
1, 1, 2, 3, 5, 8
#include <stdio.h>
void main()
{
int s1=0,s2=1; //initializing first two numbers
int nextNum=0,SumUpto=0;
printf("\n\n\tPlease enter number up to which print Fibonacci series is required \t");
scanf("%d",&SumUpto);
//here assuming user will enter value more than 1
//printing first two numbers
printf("\n\tfibbonacci Series up to %d is ",SumUpto);
printf("\n\n\t%d %d",s1,s2);
for(nextNum=2;nextNum<=SumUpto;)
{
s1=s2;
s2=nextNum;
printf(" %d",nextNum);
nextNum=s1+s2;
}
}
xxxxxxxxxx
#fibonacci series is special type of sequence
#fibonacci series is somethinng liket this-->
#0,1,1,2,3,5,8,13,21,34,55,89.......
#addition of former two succesive number results in the third element.
#in simple way as given in above series that 0,1,1--> where 0+1=1 e,i; 1
#example: 2,3,5 addition of 2 and 3 results in latter element in sequence e,i 5
8,13,21 : 8 + 13=21
34,55,89: 34 + 55=89
xxxxxxxxxx
#program to find the fibonacci series
n=int(input('Enter the number of terms in the Fibonacci series :'))
f,s=0,1
print('Fibonacci series =',f,s,sep=',',end=',')
for i in range(3,n+1):
nxt=f+s
print(nxt,end=',')
f,s=s,nxt
#output
Enter the number of terms in the Fibonacci series :7
Fibonacci series =,0,1,1,2,3,5,8,
________________________________________________________________________________
Enter the number of terms in the Fibonacci series :10
Fibonacci series =,0,1,1,2,3,5,8,13,21,34,
________________________________________________________________________________
Enter the number of terms in the Fibonacci series :4
Fibonacci series =,0,1,1,2,
xxxxxxxxxx
// FIBONACCI SERIES
// 0 1 1 2 3 5 8 13
let number = 7;
// let a=0,b =1,next;
let a=-1,b=1,next;
for(let i=1;i<=number;i++){
next= a + b;
a = b;
b = next
console.log(next)
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
cout<<"Fibonacci series upto 10 terms :- "<<endl;
int a = 0, b = 1;
int next;
for(int i=0; i<10; i++)
{
if(i==0) {
cout<<a<<" ";
continue;
}
else if(i==1)
{
cout<<b<<" ";
continue;
}
next = a + b;
a=b;
b=next;
cout<<next<<" ";
}
return 0;
}
xxxxxxxxxx
# Write a program to print fibonacci series upto n terms in python
num = 10
n1, n2 = 0, 1
print("Fibonacci Series:", n1, n2, end=" ")
for i in range(2, num):
n3 = n1 + n2
n1 = n2
n2 = n3
print(n3, end=" ")
print()