0

i dont know if this code is right because i'm trying to create a program that display the fibonacci value of a number with FUNCTIONS combining pass by the VALUE and pass by REFERENCE

#include <iostream.h>
 
void fibonacci(int, int&. int&);
 
int main()
{ int num1=0, num2=1, num, fibo;
cout<<"Enter number of fibonacci value: ";
cin>>num;
 
if(num<=0)
cout<<"invalid";
if(num==1)
cout<<"fibonacci value is"<<num1;
else if(num==2)
cout<<"fibonacci value is"<<num2; 
else
cout<<"fibonacci value of<<num<<"is" <<fibo;
fibonacci(num,num1,num2);
}
 
void fibonacci(int num, int&num1, int&num2)
{ int ctr=2,fibo;
while(ctr<num)
{fibo=num1+num2;
num1=num2;
num2=fibo;
ctr++;
}
return;
}

please help me with function,I;m really having a hard time to understand FUNCTIONS......and if you have any recommended site for function please give ! ! !!

please help ! ! !

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by thekashyap
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.