Skip to content

Instantly share code, notes, and snippets.

@psykzz
Created September 25, 2012 22:32
Show Gist options
  • Save psykzz/3784871 to your computer and use it in GitHub Desktop.
Save psykzz/3784871 to your computer and use it in GitHub Desktop.
//
// main.m
// p91e2
//
// Created by David Gardiner on 25/09/2012.
// Copyright (c) 2012 David Gardiner. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
int n, triangularNumber;
NSLog(@"Table of triangular numbers");
NSLog(@" N Triangular Number");
NSLog(@"--- -------------------");
triangularNumber = 0;
for ( n = 1; n <= 50; ++n)
{
triangularNumber += n;
if ((n%5)==0) {
NSLog(@" %2i %3i",n ,triangularNumber);
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment