473,883 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fibonacci Series

4 New Member
hi
I need help with this problem. I have tried writting the program, i just can not get it to run properly.

Please Write
The Fibonacci series
0, 1, 1, 2, 3, 5, 8, 13, 21, ...
begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms.
(a) Write a nonrecursive function fibonacci( n ) that calculates the nth Fibonacci number.

and than you
Aug 2 '06
22 123007
D_C
293 Contributor
The way integers are ordered, are non-negative numbers, in order, followed by the reversed negative range. It goes from 0 to INT_MAX, then INT_MIN to -1. Integers are 32-bit, so in Hexadecimal:
0x00000000 = 0
0x7FFFFFF = INT_MAX = -1+(2^31)
0x80000000 = INT_MIN = -(2^31)
0xFFFFFFF = -1.

INT_MAX + 1 = INT_MIN. Since Fibonacci numbers are positive, it will overflow and become negative. Modify the for statement to a while statement, and run the loop while fib is not negative (no overflow). Then variables x1 and x2, x1 < x2, will be the two most positive Fibonacci numbers an integer can support.
Aug 6 '06 #11
suresh_punniyakkodi
20 New Member
Hi,
Please follow the following program,

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5.   int a =0,b=1,c,i=2,n;
  6.   clrscr();
  7.   printf("Enter N Value : ");
  8.   scanf("%d",&n);
  9.   printf("%d\t%d\t",a,b);
  10.   while(n>i)
  11.   {
  12.     c = a+b;
  13.     printf("%d\t",c);
  14.     c=b;
  15.     b=a;
  16.     i++;
  17.   }
  18.   getch();
  19. }
Take Care,
Bye... Bye...
Aug 10 '06 #12
DrXavier
3 New Member
The easiset non recursive method I see to do this is to use a stack.

stack will always have 2 elements , both will have integers, and of course pointers.

The next element will be figured by adding the 2 integers in the stack. then you will push that on the top of the stack, and pull the header off of the stack.

I hope that made sence.
Aug 11 '06 #13
sach06jan
2 New Member
hi
I need help with this problem. I have tried writting the program, i just can not get it to run properly.

Please Write
The Fibonacci series
0, 1, 1, 2, 3, 5, 8, 13, 21, ...
begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms.
(a) Write a nonrecursive function fibonacci( n ) that calculates the nth Fibonacci number.

and than you
hello friend,
one thing is remember whenever u r doing fib series most important part is fib generate recursion that is chain is occur. so make one function is fib(). around this function write the code just like this as follows
fo=0;
f1=1
fib=fo+f1;
and display the fib.
try your self otherwise i will send u full program for fib.
thank u very much.
Sep 2 '06 #14
D_C
293 Contributor
Instead of a stack with two entries, just use two variables. Besides, there are already plenty of solutions posted here, and the iterative loop is considerably faster than using recursion.
Sep 2 '06 #15
dude dash
1 New Member
i want it in c++ not c
Feb 19 '07 #16
Banfa
9,065 Recognized Expert Moderator Expert
i want it in c++ not c
And what do you think the difference should be?
Feb 19 '07 #17
hirak1984
316 Contributor
Do you want to get hints and try yourself?

or do you want to get a readymade code,just as you buy things from shops?

i want it in c++ not c
Feb 19 '07 #18
vikasverma
1 New Member
Expand|Select|Wrap|Line Numbers
  1. // Recursive method ...Try it.
  2.  
  3. #include <iostream.h>
  4.  
  5. static int fibVal = 0;
  6. static int f0 = 0, f1 = 1;
  7.  
  8. int fib(int n)
  9. {
  10.     if(n>0)
  11.     {
  12.         fibVal = f0 + f1;    
  13.         f0 = f1;
  14.         f1 = fibVal;
  15.         cout<<f1<<endl;
  16.         n--;
  17.         fib(n);
  18.     }
  19.     return f1;
  20. }
  21.  
  22.  
  23.  
  24. void main()
  25. {
  26.     int limit;
  27.     cout<<"Please Enter the value = ";
  28.     cin>>limit;
  29.     int answer = 0;
  30.  
  31.     if(limit == 1)
  32.     {
  33.         cout<<f0<<endl;
  34.     }
  35.     else if(limit > 1)
  36.     {
  37.         cout<<f0<<endl;
  38.         cout<<f1<<endl;
  39.         answer = fib(limit - 2);
  40.     }
  41.     else if(limit <= 0)
  42.         cout<<"Please enter the value greater than 0"<<endl;
  43.  
  44. }
Jun 4 '07 #19
lakku
4 New Member
hi
I need help with this problem. I have tried writting the program, i just can not get it to run properly.

Please Write
The Fibonacci series
0, 1, 1, 2, 3, 5, 8, 13, 21, ...
begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms.
(a) Write a nonrecursive function fibonacci( n ) that calculates the nth Fibonacci number.

and than you
plese give me the program.
Jun 13 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4878
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 not? Or, another way to look at this is that: Would anyone of you think it is worth a while to find out if there is any location on earth with the set of longitude and latitude numbers that coincides with the Fibonacci series? As I see it, if...
12
2713
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 newsgroup there is an ongoing discussion about the famous fibonacci sequences, and a fine program written by a poster got my attention so just for fun I wrote one myself and put it on the web just about two days ago. It can be found on the site ...
4
4885
by: student | last post by:
Hi guys, please tell me how to write the iterative version of fibonacci series using a stack. Thanks
8
10977
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 example if the user gives 7 terms of the series to be displayed, then the display of the fibonacci series is 0, 1,1, 2, 3, 5, 8. But the natural numbers not involved are 4, 6 and 7. That's what my teacher wants. But I am struggling to write a...
2
4393
by: guneet bhatia | last post by:
please help with fibonacci series using recursion..
2
3217
by: rajeshsuri | last post by:
hi this is rajesh please send program for fibonacci series using pointers or functions
10
4023
by: omran11 | last post by:
how to generate fibonacci series (lesser than 100)
0
9936
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9791
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10845
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7970
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.