Guest User

Untitled

a guest
Jan 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #import <Foundation/Foundation.h>
  2.  
  3. int fib(int);
  4.  
  5. int main (int argc, const char * argv[])
  6. {
  7.  
  8. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  9.  
  10. int sum = 0, i = 0, x = fib(i++);
  11. while( x < 4000000 ) {
  12. if(x % 2 == 0)
  13. sum += x;
  14. x = fib(i++);
  15.  
  16. }
  17. NSLog(@"answer: %d", sum);
  18.  
  19. [pool drain];
  20. return 0;
  21. }
  22.  
  23. int fib(int n) {
  24. if( n <= 1 )
  25. return n;
  26.  
  27. return fib(n-1) + fib(n-2);
  28. }
Add Comment
Please, Sign In to add comment