Write the program for fibonacci in c++?
Answers were Sorted based on User's Feedback
Answer / kishor niit ottapalam
#include<iostream>
int main()
{
int x,y;
x=y=1;
while (x<200)
{
cout<<y<<endl;
x=x+y;
y=x-y;
}
return 0;
}
Is This Answer Correct ? | 119 Yes | 82 No |
Answer / smita
#include<iostream.h>
#include<conio.h>
class fibonacci
{
int f0,f1,f2;
public:
fibonacci()//constructor
{
f0=0;
f1=1;
f2=f0+f1;
}
void cal()
{
f0=f1;
f1=f2;
f2=f0+f1;
}
void dis()
{
cout<<"fibonacci:"<<f2<<endl;
}
};
void main()
{
fibonacci obj;
int n;
cout<<"How many no. displayed:"<<endl;
cin>>n;
for(int i=0;i<=n-1;i++)
{
obj.dis();
obj.cal();
}
getch();
}
Is This Answer Correct ? | 57 Yes | 34 No |
Answer / bharghavi
#include<iostream.h>
void main()
{
int a=-1;b=1,c;
for(int i=0;i<200;i++)
{
c=a+b;
cout<<c<<"\t";
a=b;
b=c;
}
Is This Answer Correct ? | 83 Yes | 65 No |
Answer / jitendra goyal
#include<stdio.h>
#include<conio.h>
main()
{
int a=0,b=1,n,c;
printf("how many element you want in series");
scanf("%d",&n);
printf("%d%d",a,b);
for(i=0;i<=n-2;i++)
{
c=a+b;
print("%d",c);
a=b;
b=c;
}
getch();
}
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / gobinath
#include<iostream>
using namespace std;
class A
{
public:
void print()
{
int a=0,b=1,c=0,n;
cout<<"Enter the number of : "<<endl;
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
}
};
int main()
{
A a;
a.print();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / ria
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr ();
int n,f1,f2,f3,i;
cout<<"/n input the no.of terms";
cin>>n;
f1=-1;
f2=1;
cout<<"/n the fibonacci series is ";
for(i=1,i<=n,i++)
{
f3=f1+f2;
cout<<"/n"<<f3;
f1=f2;
f2=f3;
}
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / irushad abdulrahman
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a=-1, b=1, c, x;
cout << "Enter a number to find FIBONACCI less than
that:";
cin >>x;
do
{
c=a+b;
cout << c << "\t";
a=b;
b=c;
}
while (c<=(x-c));
cout <<"\n";
system ("pause");
return 0;
}
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / srinivasan
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c=0,n;
cout<<"Enter the number: ";
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
getch();
}
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / joy
#include<iostream.h>
#include<conio.h>
voidmain()
{
clrscr();
int f1=0,f2=1,f3,n,i;
cout<<"Enter the number of terms...";
cin>>n;
cout<<"Fibonacci Series\n";
cout<<f1<<'\n'<<f2<<'\n';
for(i=3;i<=n;i++)
{
f3=f1+f2;
cout<<f3<<'\n';
f1=f2;
f2=f3;
}
getch();
}
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / gobicsk
#include <iostream>
using namespace std;
const int n = 20;
long result[n];
int fibonacci( int m )
{
if( result[m] > 0 )
// We already computed it.
return result[m];
int answer;
if( m == 0 )
answer = 0;
else
if( m == 1 )
answer = 1;
else
answer = fibonacci( m - 1 ) + fibonacci( m - 2 );
// Save answer for re-use.
result[m] = answer;
return answer;
}
int main()
{
fibonacci( n );
cout << "\n Fibonacci Series \n";
for( int i = 0; i <= n; i++ )
cout << "\n Fibonacci(" << i << ") = " << result[i];
}
Is This Answer Correct ? | 1 Yes | 0 No |
Of the numbers 12 23 9 28 which would be at the top of a properly implemented maxheap a) 28 b) 9 c) Any of them could be
Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?
What are the restrictions apply to constructors and destructors?
Do class declarations end with a semicolon? Do class method definitions?
Write about the retrieval of n number of objects during the process of delete[]p?
Is set c++?
write a program that takes 5 digit no and calculate 2 power that no and print it.
What is abstract keyword in c++?
What is the purpose of ios::basefield in the following statement?
Can a class be static in c++?
What compiler was used?
1.what is the difference between software & package &application.