-4

i cannot find the way to print the sum of all the numbers between 0 to 100 in a new line in the console. Here is my code:

NSMutableArray *intArray = [[NSMutableArray alloc] initWithCapacity:100];
    for (int i = 1 ; i <= 100 ; i ++)
        [intArray addObject:[NSNumber numberWithInt:i]];
        NSLog(@"%@", intArray); 
Xtrician
  • 504
  • 3
  • 5
  • 14

2 Answers2

3

I'm not sure why you're even using an array here. To sum the numbers between 1 and 100 just loop through that range adding the current number to a total, then print the total out.

    int total = 0;
    for (int i = 1; i <= 100; i++) {
        total += i;
    }
    NSLog(@"%i", total);
Simon Whitaker
  • 20,506
  • 4
  • 62
  • 79
2

You want to print the sum of all the integers from 1 to 100? How about:

NSLog(@"5050");
Dave DeLong
  • 242,470
  • 58
  • 448
  • 498