Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- int fib(int);
- int main (int argc, const char * argv[])
- {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- int sum = 0, i = 0, x = fib(i++);
- while( x < 4000000 ) {
- if(x % 2 == 0)
- sum += x;
- x = fib(i++);
- }
- NSLog(@"answer: %d", sum);
- [pool drain];
- return 0;
- }
- int fib(int n) {
- if( n <= 1 )
- return n;
- return fib(n-1) + fib(n-2);
- }
Add Comment
Please, Sign In to add comment