Write the program for fibonacci in c++?

Answer Posted / raaz

#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{

int range = 0;
cout<<"Enter the range of numbers\n";
cin>>range;

for(int i = 0;i<range;i++)
{

int outNum[100];
if((i==0)||(i==1))
{
outNum[i] = i;
cout<<outNum[i]<<" ";

}
else
{
outNum[i] = outNum[i-1] + outNum[i-2];
cout<<outNum[i]<<" ";

}
}

return 0;
}

Is This Answer Correct ?    13 Yes 33 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is near, far and huge pointers? How many bytes are occupied by them?

905


How do you show the declaration of a virtual constructor?

751


What is static function? Explain with an example

841


What is the difference between multiple and multilevel inheritance in c++?

908


What is the syntax for a for loop?

837


On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?

899


What is lvalue?

944


Can we declare a base-class destructor as virtual?

777


Give example of a pure virtual function in c++?

842


Explain method of creating object in C++ ?

825


What is dynamic and static typing?

906


What is the return value of the insertion operator?

881


What is a wchar_t in c++?

831


Why do we use classes in c++?

825


What is c++ library?

812