problem with fibonacci series

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srinpraveen
    New Member
    • Nov 2006
    • 19

    problem with fibonacci series

    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 program to perform this particular operation. Can anyone help?
  • palani12kumar
    New Member
    • Oct 2006
    • 60

    #2
    Try to generate the fibonacci series upto the range of the given number and store it in an array. Then using the for loop find the numbers that are not involved in the fibonacci series and print

    Comment

    • srinpraveen
      New Member
      • Nov 2006
      • 19

      #3
      Ya I know that logic but when I tried to put it down in coding, I feel that somewhere I have gone wrong in the coding. Why don't you send me the coding so that I can see if mine tallies with yours or otherwise where I have gone wrong. Later I will post my coding so that you can spot out where I am having problem because right now I am preparing for exam. In the mean time, I would appreciate if you could send in your coding for this program.

      Comment

      • Manjiri
        New Member
        • Nov 2006
        • 40

        #4
        Try out with this ... U will get the ans
        #include<stdio. h>
        int main()
        {
        int f1,f2,f3,k,n;
        printf("Enter the last element\n");
        scanf("%d",&n);
        f1=1;
        f2=2;
        f3=f1+f2;
        while(f3<n)
        {
        f1=f2;
        f2=f3;
        f3=f1+f2;
        k=f2;

        while(k<f3-1 && k<=n-1)
        {
        k++;
        printf("%4d",k) ;
        }
        }
        return 0;
        }

        Comment

        • Manjiri
          New Member
          • Nov 2006
          • 40

          #5
          Try out with this ... U will get the ans...

          #include<stdio. h>
          int main()
          {
          int f1,f2,f3,k,n;
          printf("Enter the last element\n");
          scanf("%d",&n);
          f1=1;
          f2=2;
          f3=f1+f2;
          while(f3<n)
          {
          f1=f2;
          f2=f3;
          f3=f1+f2;
          k=f2;

          while(k<f3-1 && k<=n-1)
          {
          k++;
          printf("%4d",k) ;
          }
          }
          return 0;
          }

          Comment

          • srinpraveen
            New Member
            • Nov 2006
            • 19

            #6
            thanks I will try it out soon

            Comment

            • srinpraveen
              New Member
              • Nov 2006
              • 19

              #7
              Wow, it is working...thank s a lot and I really appreciate that help

              Comment

              • Manjiri
                New Member
                • Nov 2006
                • 40

                #8
                Originally posted by srinpraveen
                Wow, it is working...thank s a lot and I really appreciate that help

                It's ok....
                And thanks for the complements...

                Comment

                • Creative
                  New Member
                  • Jan 2007
                  • 14

                  #9
                  You may try this program to get natural numbers like 4,7 in a fibonacci series:
                  #include<iostre am.h>
                  #include<conio. h>
                  int main()
                  {
                  clrscr();
                  unsigned long a,b,c,n;
                  a=2;
                  b=1;
                  cout<<"How many numbers(>5)?"<< "\n";
                  cin>>n;
                  cout<<"Fibonacc i series"<<"\n";
                  cout<<a<<b;
                  for(int i=2,i<n;i++)
                  {
                  c=a+b;
                  cout<<c;
                  a=b;
                  b=c;
                  }
                  getch();
                  return 0;
                  }


                  The Output will be as:
                  2134711

                  By giving b=2,You will get the output as:
                  22461016
                  In this way you can get the natural numbers like 4,6,7 in a fibonacci series.

                  We can't get a series with 4,6,7 coming together,since the sum of 4 and 6 will certainly give as 10 and not as 7.
                  I hope that this helped you.

                  Comment

                  Working...