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

Why can’t you call invariants() as the first line of your constructor?

564


Explain data encapsulation?

612


Are strings immutable in c++?

659


What is stream and its types in c++?

564


Why ctype h is used in c++?

527






What are the advantages of prototyping?

569


What is a down cast?

613


What is linked list in c++?

695


Explain rtti.

596


What is the need of a destructor? Explain with the help of an example.

570


What is the auto keyword good for in c++?

626


What are vtable and vptr?

625


How do you establish a has-a relationship?

611


Can you please explain the difference between using macro and inline functions?

538


Is swift better than c++?

542