-
Notifications
You must be signed in to change notification settings - Fork 3
Objc: Loops
Alfie Hanssen edited this page Nov 21, 2013
·
2 revisions
int main(int argc, char * argv[])
{
@autoreleasepool {
// ...
NSArray *numbers = @[@10, @20, @25, @100];
float sum = 0.0f;
for (int i = 0; i < [numbers count]; i++) {
NSNumber *number = numbers[i];
sum = sum + [number intValue];
}
float average = sum / [numbers count]; // Should be 38.75
NSLog(@"average = %.2f", average);
// UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
2013-11-17 14:41:37.520 ObjcBasics[13163:a0b] average = 38.75