Thread: call a function

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    16

    call a function

    My program prints out Fibonacci_number(0,1,1,2,3,5). The program is ok.
    My problem:I want to take a number from Fibonacci_number(0,1,1,2,3,5)
    and multiply whit 10. ex: I want to take 3 and multiply with 10.
    I tried to write another function and call a Fibonacci_number from fib(int k)
    and then multiply it whit 10.
    How can I call an exact Fibonacci_number.

    Code:
    int fib(int k)
    {
          
    	  int my_nbr=0;
    	  int f;
    	  
              int  nbr1 = 0;
              int  nbr2 = 1;
              printf("0,1");
    
           
          for (f = 2; f < k; ++f)
           {
               printf(",%d", nbr1 + nbr2);
    		     
    
               my_nbr= nbr2;
               nbr2 = nbr2 + nbr1;
               nbr1 = my_nbr;
    
    		
           }
      printf("\n");
     
    }
    
    int main(void)
    {
       fib(6);
      
       return 0;
    }
    Last edited by peterx; 10-18-2005 at 06:54 AM. Reason: ***

  2. #2
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    well you have int fib(int k); so you want fib to return an int, so at the end you should have it return the fib number for the Kth iteration.

    Then you can simply do:
    Code:
    int foo = 10*fib(bar);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM