hey..
can u help me wid this..
#include<stdio.h>
#include<conio.h>
void main()
{
int fib(int);
int n,f=1,ans;
clrscr();
while(f==1)
{
printf("\n***Generating A Fibonacci Series***");
printf("\nEnter Number Of Terms Required: ");
scanf("%d",&n);
if(n<=1)
{
printf("\nInvalid Choice..Number Of Terms Should Be more Than 1");
printf("\nDo You Want To Try Again...\n1.Yes\n2.No");
scanf("%d",&f);
}
else
{
printf("\nSeries: %d",fib(n));
f=2;
}
}
getch();
}
int fib(int a)
{
if((a==0)||(a==1))
{
return(1);
}
else
{
return(fib(a-1)+fib(a-2));
}
}
i wat to print d numbers as well...eg if n =5
1 1 2 3 5
14 2216 @Tired
You what to what?
void fibfib(int n)
{
int q;
if(q=n-1)fibfib(q);printf("%d ",fib(q));
}
wat=*want...
umm i dint understand the func u hv typed..can u help me with understanding it???it wud b great if u can..
thnx..
@Tired
Please spell your words properly; this is an international forum not your local text speak community.
kind regards,
Jos
I am sorry...but can u please help me understand this...
void fibfib(int n)
{
int q;
if(q=n-1)fibfib(q);printf("%d ",fib(q));
}
@Tired
Note that fib() is your function; the function fibfib() is just defined for printing the return values of your function. Try it by hand for small values of n. Also note that the expression q=n-1 is non-zero when n != 1
kind regards,
Jos
But its not printing all the values(or the entire series). Its just printing the final answer.Where should i call this function?in the main block before i am printing my answer?
And most of the times its not printing any thing.
@Tired
How strange; to be sure I ran it as well and it runs fine, i.e. it prints out the first n values of the standard Fibonacci series. Can you show us some code?
kind regards,
Jos
#include<stdio.h>
#include<conio.h>
void main()
{
int fib(int);
void fibfib(int);
int n,f=1,ans;
clrscr();
while(f==1)
{
printf("\n***Generating A Fibonacci Series***");
printf("\nEnter Number Of Terms Required: ");
scanf("%d",&n);
if(n<=1)
{
printf("\nInvalid Choice..Number Of Terms Should Be more Than 1");
printf("\nDo You Want To Try Again...\n1.Yes\n2.No");
scanf("%d",&f);
}
else
{
fibfib(n);
printf("\nAns i.e. term no. %d = %d",n,fib(n));
printf("\nDo You Want To Continue:\n1.Yes\n2.No\n");
scanf("%d",&f);
}
}
}
int fib(int a)
{
if((a==0)||(a==1))
return(1);
else
return(fib(a-1)+fib(a-2));
}
void fibfib(int a)
{
int q;
if(q=a-1)
fibfib(q);
else
printf("%d ",fib(q));
}
this is the code i tried.....
@Tired
I don't see an 'else' in the original code ...
kind regards,
Jos
it doesnt work without else also!!!i tried..so then is that last print statement not a part of the for loop??and is the way i am calling the function right??
@Tired
Don't shout; there is no need to start a "yes it does, not it doesn't" discussion. You have to show or prove that it doesn't work; at least show the code you used. I also ran it and it worked for me (both in C and C++, my Java version also ran correctly).
kind regards,
Jos
i have tried ur code..no problem with that.
But i would like to advise u that without detecting if the user want to continue by pressing 1 or Y or 2 or N.Use isdigit to differentiate them else if when alphabet is pressed the loop will keep on going
hey khaichiew85,
so u mean that the "fibfib" func is displaying the series for u?can u help with the calling statement and evrything??
regards
Amy
@Tired
There is no need for help: I simply copied/pasted that fibfib function, crafted a loop around it and voila. Why don't you show your code? We are not going to spoonfeed you complete programs.
kind regards,
Jos (moderator)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brett Trost |
last post by:
OK, I wanted to make a recursive fibonacci method in Perl, and I can't
understand why it is not working, especially since I wrote the exact
same thing in Java and it works. Here's the perl code:
...
|
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,...
|
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...
|
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;...
|
by: greek |
last post by:
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...
|
by: veeru |
last post by:
Hi All,
Can anyone tell about how to create a FIBONACCI series in VB.Net and C#
Thanks in Advance,
Veeru
|
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...
|
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...
|
by: guneet bhatia |
last post by:
please help with fibonacci series using recursion..
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |