// 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;
}
Denver Cupido 0 Newbie Poster
Excizted 67 Posting Whiz
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
jonsca 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
Excizted 67 Posting Whiz
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.