#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSMutableArray *arr = [NSMutableArray arrayWithArray:@[@1,@3,@5,@7,@9]];
long count = arr.count;
NSLog(@"请输入一个正数:");
int input;
scanf("%d",&input);
NSNumber *c = [NSNumber numberWithInt:input];
for (int i = 0; i < count; i++) {
if([c compare:arr[i]]<=0){
[arr insertObject:c atIndex:i];
break;
}
}
if (arr.count == count) {
[arr addObject:c];
}
NSLog(@"%@",arr);
}
return 0;
} |
|