Amazon.com Widgets Chapter 5, Exercise 3
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2013, 05:01:53 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 5
| | | |-+  Chapter 5, Exercise 3
Pages: [1]   Go Down
Print
Author Topic: Chapter 5, Exercise 3  (Read 346 times)
Alistair
Newbie
*
Posts: 18






« on: April 12, 2011, 02:54:12 AM »

Mine's a bit more complicated than others in here (they always are lol) but I tried to follow the example in the book and work down from the Integer rather than up. It gave me some practise using a while loop as well as a for loop Smiley

Code: (Objective-C)

#import <Foundation/Foundation.h>


int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
       
    int n, c, r;
   
    NSLog (@"Table of Factorials");
    NSLog (@"Integer        Factorial");
    NSLog (@"------------------------");
   
    for (n = 1; n <= 10; ++n)
    {
        c = n;
        r = n;       
        while (c-1 > 0)
        {
            r = r*(c-1);
            --c;
        }
       
        NSLog (@"%2i       %i", n, r);
    }

    [pool drain];
    return 0;
}
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.