473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

fibonacci series using recursion.. error not an allowed type

17
Hi!
I hav to generate fibonaaci series using recursion:
0,1,1,2,3,5,8,18,21...
whr
fibonacci(0)=0
fibonacci(1)=1
fibonacci(n)=fibonacci(n-1)+fibonacci(n-2)

ive witten the code but having 2 errors:

#include<iostream.h>
#include<conio.h>
void fibonacci(int i);
int n,x,f;
void main()
{clrscr();
for(n=0;n<100;n++)
fibonacci(x);
getch();
}

void fibonacci(int i)
{if(i==0)
f=0;
else if(i==1)
f=1;
else
f=fibonacci(i-1)+fibonacci(i-2); // NOT AN ALLOWED TYPE
}


the error is not an allowed type..wats that???
Nov 19 '06 #1
3 14771
horace1
1,510 Expert 1GB
as you are using the function fibonacci() in the expression
Expand|Select|Wrap|Line Numbers
  1. f=fibonacci(i-1)+fibonacci(i-2); // NOT AN ALLOWED TYPE
  2.  
it should return an int as the function result not void, e.g.
Expand|Select|Wrap|Line Numbers
  1. int fibonacci(int i)
  2. {if(i==0)
  3. f=0;
  4. else if(i==1)
  5. f=1;
  6. else
  7. f=fibonacci(i-1)+fibonacci(i-2); // NOT AN ALLOWED TYPE
  8. }
  9.  
Nov 19 '06 #2
greek
17
as you are using the function fibonacci() in the expression
Expand|Select|Wrap|Line Numbers
  1. f=fibonacci(i-1)+fibonacci(i-2); // NOT AN ALLOWED TYPE
  2.  
it should return an int as the function result not void, e.g.
Expand|Select|Wrap|Line Numbers
  1. int fibonacci(int i)
  2. {if(i==0)
  3. f=0;
  4. else if(i==1)
  5. f=1;
  6. else
  7. f=fibonacci(i-1)+fibonacci(i-2); // NOT AN ALLOWED TYPE
  8. }
  9.  
Ok thx but now the problem is that when im cout the fibonacci(x)
i get only a list of zeros..the fibonacci series is not being generated
wat do i do?
Nov 19 '06 #3
horace1
1,510 Expert 1GB
Ok thx but now the problem is that when im cout the fibonacci(x)
i get only a list of zeros..the fibonacci series is not being generated
wat do i do?
in main() your loop counter is n but you call fibonacci with paramater x, it should be n, e.g.
Expand|Select|Wrap|Line Numbers
  1. for(n=0;n<10;n++)
  2. cout << fibonacci(n)<< endl;
  3.  
you also need to return f at the end of fibonacci
Nov 19 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: dleecurt | last post by:
Hello, I have a small problem, I am trying to write a program that will calculate the Fibonacci number series, and I have the code complete with one problem. I used a long in to store the numbers,...
4
by: YS Sze | last post by:
If you know the exact longitude and latitude for a specific location, would anyone think it'd make any sense to find out if this set of location numbers is really part of the Fibonacci series or...
12
by: CII | last post by:
Hi everybody. I've been reading posts a year old about the fibonacci series right on this newsgroup, and while it's not directly games related, I'll share my own notes as well. On another...
11
by: MARQUITOS51 | last post by:
Hey guys this is the fibonacci series. But Im having this huge problem. First of all I want to do the simplest code possible so then I can use user defined functions and arrays. But this one didnt...
14
by: felixnielsen | last post by:
Im actually kinda embarassed to ask this question... @code start #include <iostream> int main() { unsigned long long a = 1; unsigned long long b = 1; for (int i = 0; i < 45; i++) { a += b;...
8
by: srinpraveen | last post by:
I know to write a program to print the fibonacci series. But the problem is my teacher has asked us to write a program to print the natural numbers that are not involved in the fibonacci series. For...
6
by: deepner | last post by:
plz help to find why the program showing fibonacci(non-recursively) is running infinitely #include<iostream> #include<conio.h> using namespace std; unsigned int fibo(int a,int b) { unsigned...
17
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
2
by: guneet bhatia | last post by:
please help with fibonacci series using recursion..
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.