代码清单5-4

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\n", number, triangularNumber);

你可能感兴趣的:(代码清单5-4)