#import <Foundation/Foundation.h>
@interface Factorial : NSObject
+(int) factorial:(int) n;
@end
@implementation Factorial
+(int) factorial:(int)n
{
if (n==0) {
return 1;
}
else
{
return [self factorial:n]*[self factorial:n-1];
}
}
@end
int main (int argc, const char * argv[])
{
int i = [Factorial factorial:5];
NSLog(@"%d", i);
return 0;
}
В чем проблема с этим кодом? Я новичок в объективе-c (я с фона c) Или, я получаю неправильную концепцию о объективе c ??Рекурсивный факториал
(Compiler generating ..)
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys002
sharedlibrary apply-load-rules all
[Switching to process 1413 thread 0x0]
warning: Unable to restore previously selected frame.
(gdb)
и застрять на линии + (INT) факториала: (Int) п в @implementation результате EXC_BAD_ACESS.
Благодаря
Что компилятор говорит вам? – huon
Вы расскажете нам, в чем проблема, и мы поможем вам исправить это. :) – whooops