0
Code to do Fibonacci
Please help me https://code.sololearn.com/cYh0lW55Hs6a/?ref=app
6 Respuestas
+ 1
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int a=0,b=1,c;
System.out.println ("enter end value");
int n=sc.nextInt();
System.out.print (a+" "+b);
for (int i=3;i<=n;i++)
{
c=a+b;
System.out.print(" "+c);
a=b;
b=c;
}
}
}
0
Help
0
Big thanks for you shaswat
0
😁
0
Wlcm bro
0
#fibonacci program in c
#include<stdio.h>
int main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);//printing 0 and 1
for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
return 0;
}