Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8 13 21 34 55 ....... and also need add code complexity time if you want!
here code.c
---------------------------------------------------------------------------------------------------------------------
#include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[ n + 1 ]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i < n; i++ ) { fib[ i ] = fib[ i - 1 ] + fib[ i - 2 ]; } return fib[ n ]; } void main ( int argc, char * argv[ ] ) { int n; int i; printf("Enter number: "); scanf("%d", &n); printf("Fibonacci Iteratiion is \n"); for ( i = 0; i < 20; i++ ) { printf("%d: %d\n", i, fibonacciIterative( n )); } printf("Press key any continue...\n"); }
---------------------------------------------------------------------------------------------------------------------
#include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i <= n; i++ ) { fib[ i ] = fib[ i - 1 ] + fib[ i - 2 ]; } return fib[ n ]; } void main ( int argc, char * argv[ ] ) { int n; int i; printf("Enter number: "); scanf("%d", &n); printf("Fibonacci Iteratiion is \n"); for ( i = 0; i <= n; i++ ) { printf("%d: %d\n", i, fibonacciIterative( i )); } printf("Press key any continue...\n"); }
////////////////////////////////////////////////// // Time complexity = O(n^2)
Get Answers For Free
Most questions answered within 1 hours.