R
Ram Prasad
I have a simple demo program that demonstates use of recursion ( on linux )
The problem is that it does not work for "long" integers. I assume this is a problem with printf
I tried %l instead of %d but that doesnot print any integer.
########## This is fine
../fib 10000
50005000
######### Oops this is not working
../fib 100000
705082704
----------------
#include <stdio.h>
#include <stdlib.h>
long fibonacci(long n) {
return ((n == 1 ) ? 1 : (n + (fibonacci(n - 1 ))));
}
int main(int argc , char *argv[]) {
long n = atol(argv[1]);
printf("%d\n",fibonacci(n));
}
The problem is that it does not work for "long" integers. I assume this is a problem with printf
I tried %l instead of %d but that doesnot print any integer.
########## This is fine
../fib 10000
50005000
######### Oops this is not working
../fib 100000
705082704
----------------
#include <stdio.h>
#include <stdlib.h>
long fibonacci(long n) {
return ((n == 1 ) ? 1 : (n + (fibonacci(n - 1 ))));
}
int main(int argc , char *argv[]) {
long n = atol(argv[1]);
printf("%d\n",fibonacci(n));
}