Skip to content

Instantly share code, notes, and snippets.

@98chimp
Last active August 29, 2015 14:16
Show Gist options
  • Save 98chimp/b69590e4987f650d5964 to your computer and use it in GitHub Desktop.
Save 98chimp/b69590e4987f650d5964 to your computer and use it in GitHub Desktop.
Fibonacci
//
// main.c
// Fibonacci
//
// Created by Shahin on 2015-03-11.
// Copyright (c) 2015 98% Chimp. All rights reserved.
//
#include <stdio.h>
int recursiveValueFibonaci(int remainingSteps, int previousNumber, int previousPreviousNumber) {
if (remainingSteps <= 0) return 0;
printf("%d\n",previousPreviousNumber);
recursiveValueFibonaci(remainingSteps - 1, previousPreviousNumber, previousNumber + previousPreviousNumber);
return 0;
}
int main(int argc, const char * argv[]) {
# pragma mark - Iteration
// int input, firstNumber = 0, secondNumber = 1, nextNumber, counter;
//
// printf("Enter the number of terms\n");
// scanf("%d",&input);
//
// printf("First %d terms of Fibonacci series are :-\n",input);
//
// for ( counter = 0 ; counter < input ; counter++ )
// {
// if ( counter <= 1 )
// nextNumber = counter;
// else
// {
// nextNumber = firstNumber + secondNumber;
// firstNumber = secondNumber;
// secondNumber = nextNumber;
// }
// printf("%d\n",nextNumber);
// }
# pragma mark - Recursion
recursiveValueFibonaci(12, 1, 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment