Amazon.com Widgets Chapter 5 Exercise 8
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 20, 2013, 12:43:29 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 8
Pages: [1]   Go Down
Print
Author Topic: Chapter 5 Exercise 8  (Read 407 times)
Alistair
Newbie
*
Posts: 18






« on: April 12, 2011, 03:54:34 AM »

Here is my solution for chapter 8, adapted from Program 5.8

Code: (Objective-C)

#import <Foundation/Foundation.h>

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

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int number, right_digit, sum;
    //right_digit = 0;
    sum = right_digit;
   
    NSLog (@"Enter your number.");
    scanf ("%i", &number);
   
    while (number != 0)
    {
        right_digit = number % 10;
        number /= 10;
        sum += right_digit;
    }

    NSLog (@"The sum of the digits is %i", 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.