Write the program for fibonacci in c++?

Answers were Sorted based on User's Feedback



Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Write the program for fibonacci in c++?..

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

Post New Answer

More C++ General Interview Questions

Why we use #include iostream in c++?

0 Answers  


What are the different operators in C++?

3 Answers   HP,


Define virtual constructor.

0 Answers  


What is the difference between #import and #include?

0 Answers  


What does flush do c++?

0 Answers  






How do I use turbo c++?

0 Answers  


Write a program to calculate the BMI of a person using the formula BMI = weight/height2.

2 Answers  


Why are pointers not used in c++?

0 Answers  


What are the basic data types used in c++?

0 Answers  


What and all can a compiler provides by default?

3 Answers   Accenture, HP,


Write a program to concatenate two strings.

0 Answers  


class professor {}; class teacher : public virtual professor {}; class researcher : public virtual professor {}; class myprofessor : public teacher, public researcher {}; Referring to the sample code above, if an object of class "myprofessor" were created, how many instances of professor will it contain? a) 0 b) 1 c) 2 d) 3 e) 4

4 Answers   Quark,


Categories