19 Replies - 513 Views - Last Post: 03 February 2013 - 10:22 AM
#1
Question about Fibonacci Sequence.
Posted 15 January 2013 - 09:10 AM
When I input 1 the output should be:
1
1
2
3
5
8
13
21
34
55
89
Replies To: Question about Fibonacci Sequence.
#2
Re: Question about Fibonacci Sequence.
Posted 15 January 2013 - 09:11 AM
Jim
#3
Re: Question about Fibonacci Sequence.
Posted 15 January 2013 - 09:45 AM
This post has been edited by Aphex19: 15 January 2013 - 03:12 PM
#4
Re: Question about Fibonacci Sequence.
Posted 15 January 2013 - 02:50 PM
But what I did is just showing:
1
2
3
4
5
6
7
8
9
10
11
Can't understand how to insert the sequence
#5
Re: Question about Fibonacci Sequence.
Posted 15 January 2013 - 02:57 PM
I got the website now.
I really appreciate your reply.
#6
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 08:44 AM
#include<stdio.h>
#include<conio.h>
main()
{
int var,a=0,b=1,c,sum=1,d;
clrscr();
printf("Enter an integer: ");
scanf("%i",&var);
var=d;
for(var=1;var<=11;var++)
{
c=a+b;
sum=sum+c;
printf("\n%i",c);
b=c;
a=b;
if(c==d)
break;
else
continue;
}
getch();
}
The output is just showing: 1,2,4,8,16,31,64....
The Output that I need is: 1,1,2,3,5,8,13,21,34,55,89,
Pls reply....
This post has been edited by jimblumberg: 19 January 2013 - 08:52 AM
Reason for edit:: Added missing code tags. Please learn to use them properly.
#7
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 08:55 AM
Jim
#8
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 08:59 AM
#9
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 11:36 AM
#10
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 11:48 AM
You have :
09 printf("Enter an integer: ");
10 scanf("%i",&var);
I think you want the maximum value of Fibonacci number to print. So something like :
09 printf("Enter the maximum value of Fibonacci number to print : ");
10 scanf("%i", &max_fibonacci);
Wikipedia said:
so something like :
subsequent_number = previous_1 + previous_2; /* or */ current_number = previous_1 + previous_2; /* or */ fibonacci_number = previous_1 + previous_2;
This post has been edited by #define: 19 January 2013 - 11:49 AM
#11
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 11:53 AM
#12
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 02:00 PM
#include<stdio.h>
#include<conio.h>
main()
{
int num=0,a=0,b=1,count=0;
printf("How many number you want? (3minimum):");
scanf("%d",&num);
printf("0\n1");
do{b=a+b;a=b-a;b=a+b-a;count++;
printf("\n%d",B)/>/>;
}
while(count<=num-3);
printf("\n");
return 0;
}
getch();
This post has been edited by jimblumberg: 19 January 2013 - 07:14 PM
Reason for edit:: Added missing code tags. Please learn to use them properly.
#13
Re: Question about Fibonacci Sequence.
Posted 19 January 2013 - 07:15 PM
Jim
This post has been edited by jimblumberg: 19 January 2013 - 07:15 PM
#14
Re: Question about Fibonacci Sequence.
Posted 20 January 2013 - 02:30 AM
#15
Re: Question about Fibonacci Sequence.
Posted 20 January 2013 - 07:14 AM
You need to find an indentation style you like and use it consistently. This will make reading your program much easier.
Here is your code reformatted:
#include<stdio.h>
#include<conio.h>
main()
{
int num=0,a=0,b=1,count=0;
printf("How many number you want? (3minimum):");
scanf("%d",&num);
printf("0\n1");
do {
b=a+b;
a=b-a;
b=a+b-a;
count++;
printf("\n%d",b );
}
while(count<=num-3);
printf("\n");
return 0;
}
getch();
And here are the error messages I get when I compile your code:
Quote
main.c|3|error: return type defaults to ‘int’|
main.c|21|error: data definition has no type or storage class|
main.c|21|error: type defaults to ‘int’ in declaration of ‘getch’|
main.c|21|warning: redundant redeclaration of ‘getch’ [-Wredundant-decls]|
conio.h|28|note: previous declaration of ‘getch’ was here|
||=== Build finished: 4 errors, 1 warnings ===|
Jim
|
|

New Topic/Question
Reply



MultiQuote





|