Amazon.com Widgets My code for Exercise 4
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 07:24:33 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 4
| | | |-+  My code for Exercise 4
Pages: [1]   Go Down
Print
Author Topic: My code for Exercise 4  (Read 425 times)
darrinaltman
Newbie
*
Posts: 7


Email




« on: September 11, 2011, 04:23:16 PM »

I know this isn't the most efficient and obviously not the best way to solve this but here is how I approached it.  Please critique.  All comments welcomed, especially critical comments.


#import <Foundation/Foundation.h>

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

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    double x;
    double result1;
    double result2;
    double sum;
   
    x = 2.55;
    result1 = 1;
    result2 = 1;
   
    for (int i = 0; i < 3; i++) {
        result1 *= x;
    }
    for (int j = 0; j < 2; j++) {
        result2 *= x;
    }
   
    sum = 3 * result1 - 5 * result2 + 6;
    NSLog(@"\nThe answer is: %g.", sum);

    [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.