int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int n, number, triangularNumber;
NSLog(@"What Triangular Number Do You Want?");
scanf(@"%i", &number);
triangularNumber = 0;
for (n = 1; n <= number; ++n)
triangularNumber += n;
NSLog(@"Triangular Number %i is %i", number, triangularNumber);
[pool drain];
return 0;
}
The output when I write an integer is this:
Triangular Number 0 is 0
Your input number is 0, and your condition in the for loop starts at 1. Therefore, the loop is never executed.