0% found this document useful (0 votes)
48 views3 pages

Sirul Lui Fibonacci

The document contains 3 C++ programs that work with the Fibonacci sequence. The first program prints the Fibonacci sequence up to a given number. The second finds the largest Fibonacci number smaller than a given number. The third writes a given number as the sum of Fibonacci numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views3 pages

Sirul Lui Fibonacci

The document contains 3 C++ programs that work with the Fibonacci sequence. The first program prints the Fibonacci sequence up to a given number. The second finds the largest Fibonacci number smaller than a given number. The third writes a given number as the sum of Fibonacci numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

//sirul lui Fibonacci


#include <iostream>
using namespace std;
int main()
{ int nr,a,b,c,i;
cin>>nr;
if(nr==1)
cout<<1;
else
if(nr==2)
cout<<1<<" ";
else
{ a=1;
b=1;
cout<<a<<" "<<b<<" ";
for(i=3; i<=nr; i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
}
return 0;}
2.
// cel mai mare numar din sirul lui Fibonacci mai mic decat un numar dat
#include <iostream>

using namespace std;

int main()
{
int x,a,b,c;
cin>>x;
a=1;
b=1;
while(a+b<x)
{
c=a+b;
a=b;
b=c;
}
cout<<c;
return 0;
}
3.
//scrierea unui numar ca suma de termeni din sirul Fibonacci
#include <iostream>

using namespace std;

int main()
{
int n,a,b,c;
cin>>n;
while(n>0)
{
a=0;
b=1;
while(a+b<=n)
{
c=a+b;
a=b;
b=c;
}
cout<<c<<" ";
n=n-c;
}
return 0;
}

You might also like