Question about Fibonacci Sequence.

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 698 Views - Last Post: 03 February 2013 - 10:22 AM Rate Topic: -----

#16 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,531
  • Joined: 09-June 09

Re: Question about Fibonacci Sequence.

Posted 20 January 2013 - 02:52 PM

The fibonacci sequence is naturally defined recursively. Maybe if you implement it recurisivly first, then you will understand your problems with your iterative solution.
Was This Post Helpful? 0
  • +
  • -

#17 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Question about Fibonacci Sequence.

Posted 20 January 2013 - 09:03 PM

Well, here are some suggestions I have for your code. I have indicated them in comment lines.

#include<stdio.h>
#include<conio.h>
main()// should be int 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; //This statement seems to be redundant here as a will get cancelled by -a
      count++;
      printf("\n%d",b );
   }
   while(count<=num-3);
   printf("\n");
   return 0;
}// wrong closing of braces
getch();
//braces must close here



regards,
Raghav
Was This Post Helpful? 1
  • +
  • -

#18 johnpaulbb02  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 15-January 13

Re: Question about Fibonacci Sequence.

Posted 03 February 2013 - 09:48 AM

I created this one:

[
#include<stdio.h>
#include<conio.h>

main()
 {
    int x,val;

    clrscr();
    printf("Enter value:");
    scanf("%i",&val);
    x=1;
    do
    {
    printf("\n%i",x);
    x++;
    }
      while(x<=val);
      getch();

 }

]

can you help me to insert a code that will add the sequence?

This post has been edited by jimblumberg: 03 February 2013 - 10:00 AM
Reason for edit:: Added missing code tags. Please learn to use them properly.

Was This Post Helpful? -1
  • +
  • -

#19 jimblumberg  Icon User is offline

  • member icon


Reputation: 3987
  • View blog
  • Posts: 12,298
  • Joined: 25-December 09

Re: Question about Fibonacci Sequence.

Posted 03 February 2013 - 10:00 AM

Use code tags when posting code! And you need to show some actual effort at solving your problem.

Jim
Was This Post Helpful? 0
  • +
  • -

#20 johnpaulbb02  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 15-January 13

Re: Question about Fibonacci Sequence.

Posted 03 February 2013 - 10:22 AM

Let me try jim.
thanks for the reply
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2