Non-recursive Iteration and Recursion/Lab1.c
unsigned long long int fibonacci(unsigned int n){
  unsigned long long int results = 1;  //we initialize results to 1 because our seq. starts at 1
  
  int prev = 1, pprev = 1;  //var prev is the previous num in the sequence and is seeded with 1
                            //var pprev is the 2nd previous num in the sequence and is seeded with 1
  
  if(n == 0 || n == 1) return n;  //tests base cases as the fib. seq. of 0 is 0 and 1 is 1
  
  //Iteratively calculates the fib. seq. of the input number
  for (int i = 1; i <= n; i++){
    //we already know the first 2 position results of the seq. is 1 and 1, so we just need to calc. from the 3rd position
    if(i >= 3){
        results = (prev) + (pprev);
        pprev = prev;
        prev = results;
    }
  }
  return results;
}
/*
  fibonacci: generates the fibonacci sequence for a positive integer e.g 4: fibonacci(10) = 55
             starting sequence number is chosen to be 1.
  Input: a positive integer (n) where n is the number of sequences
  Output: results
*/
generates the fibonacci sequence for a positive integer e.g 4: fibonacci(10) = 55
starting sequence number is chosen to be 1.
Input: a positive integer (n) where n is the number of sequences
Output: results
generates the fibonacci sequence for a positive integer e . g 4 : fibonacci ( 10 ) = 55 starting sequence number is chosen to be 1 . Input : a positive integer ( n ) where n is the number of sequences Output : results
unsigned long long int fibonacci(unsigned int n){
  unsigned long long int results = 1;  
  int prev = 1, pprev = 1;  
  if(n == 0 || n == 1) return n;  
  for (int i = 1; i <= n; i++){
    if(i >= 3){
        results = (prev) + (pprev);
        pprev = prev;
        prev = results;
    }
  }
  return results;
}
unsigned long long int fibonacci ( unsigned int n ) { unsigned long long int results = 1 ; int prev = 1 , pprev = 1 ; if ( n == 0 || n == 1 ) return n ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i >= 3 ) { results = ( prev ) + ( pprev ) ; pprev = prev ; prev = results ; } } return results ; }
fibonacci: generates the fibonacci sequence for a positive integer e.g 4: fibonacci(10) = 55
starting sequence number is chosen to be 1.
fibonacci : generates the fibonacci sequence for a positive integer e . g 4 : fibonacci ( 10 ) = 55 starting sequence number is chosen to be 1 .
//we initialize results to 1 because our seq. starts at 1 //var prev is the previous num in the sequence and is seeded with 1 //var pprev is the 2nd previous num in the sequence and is seeded with 1 //tests base cases as the fib. seq. of 0 is 0 and 1 is 1 //Iteratively calculates the fib. seq. of the input number //we already know the first 2 position results of the seq. is 1 and 1, so we just need to calc. from the 3rd position