// fibonacci2.cpp : Defines the entry point for the console application.

#include "stdafx.h" 
#include<iostream>
using namespace std;
	 
int fibonacci(int n)//declare function
{
	//declare variables 
                int x1 = 0;
	int	fib ;
	int x2 = 1;	


	if(n >= 1)
	{


	
		for(int i=2;i<= n; i++)
		{
		fib = x1 + x2;	
		x1 = x2;
		x2 = fib;
		}

	}



return fib;	//end function
}



int main()	//declare main function
{
for(int i=2; i <=10; i++)
{
cout<<fibonacci(i)<<endl;
}
return 0;
}

Recommended Answers

All 3 Replies

Yeah I know how to post code here too :) and code tags... impressive.

I did the code tags...

commented: "with all the help about them, how could you miss using them????" -- Dr. Walter P Codetags (I'm thinking of starting a WaltP quote wall somewhere) +2

+rep WaltP :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.