can you write me a program for this plss

+1 vote
asked Apr 3, 2019 by anonymous
First 2 terms will be constant 0 and 1 in Fibonacci series. Each new term in the Fibonacci sequence is generated by adding the previous two terms. Compute the Fibonacci series up to 15 numbers e.g. 1, 2, 3, 5, 8, 13, 21, 34, 55,89,….

4 Answers

+1 vote
answered Apr 3, 2019 by Abhay Pandey
#Program to compute first 15 numbers of the fibonacci series

#!/usr/bin/env/python3

def fibonacci(n):
    if n < 0:
        print("wrong input")
    elif n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)

for i in range(0, 15):
    print(fibonacci(i))
0 votes
answered Apr 12, 2019 by vishvajeet
#include<stdio.h>
int main(void)
{
    int x[100],n=15,i,j,a;
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            if(j<=2)
              {
                  x[j]=j+1;

a=a+x[j];               
              }
              
                  x[i+2]=x[i]+x[i+1];

a=a+x[i];            
            
        }
    }
    printf("\nseries are:");
    for(i=0;i<n;i++)
    {
        printf("%d\t",x[i]);
    }

printf("\n sum of series no.:%d",a);   
    return 0;
0 votes
answered Apr 12, 2019 by yashetty29 (140 points)
edited Apr 12, 2019 by yashetty29

Assuming Language required C it will not compute 15 no you can define how many no you want to compute for

#include<stdio.h>
void main()
{
int n,new,i;
int a[2]={0,1};
printf("Enter the no up to where you want to find the series\n");
scanf("%d",&n);

printf(" Fibonacci series\n0\n1\n");
for(i=3;i<=n;i++)
{
new=a[0]+a[1];
printf("%d\n",new);
a[0]=a[1];
a[1]=new;
}
}

0 votes
answered Apr 17, 2019 by ram
#include<iostream>

using namespace std;

int main()

{

int n1=0,n2=1,n3,num,i;

cout<<"enter the number";

cin>>num;

cout<<n1<<" "<<n2<<" ";

for(i=1;i<=num;i++)

{

n3=n1+n2;

n1=n2;

n2=n3;

cout<<n3<<" ";

}

return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...