Amazon.com Widgets Is this solution to 5.8 too short? Seems to work though.
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 19, 2013, 01:43:38 AM
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
|-+  Programming in Objective-C, 4th edition
| |-+  Exercises
| | |-+  Chapter 5
| | | |-+  Is this solution to 5.8 too short? Seems to work though.
Pages: [1]   Go Down
Print
Author Topic: Is this solution to 5.8 too short? Seems to work though.  (Read 432 times)
Bensch
Newbie
*
Posts: 5






« on: August 08, 2012, 07:15:46 AM »


Code: (Objective-C)
#import <Foundation/Foundation.h>

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

    @autoreleasepool {
       
        int number, sum;
   
        NSLog(@"Enter your number.");
        scanf ("%i",&number);
       
        sum = 0;
       
        while (sum != 0) {
            sum = sum + (number % 10);
            number /= 10;
        }
        NSLog (@"%i", sum);
        }
                       return 0;
}

Logged
microapple
Jr. Member
**
Posts: 83



WWW Email




« Reply #1 on: August 15, 2012, 08:34:50 PM »

Code: (Objective-C)
 
sum = 0; 
while (sum != 0)

did this quote remind you something ?
in reality your program will never enter the loop !
because the condition is false sum is always zero
and the loop enter while sum is not zero !

and the exercise want you to ask the user how many time he will
give a number to find its number of triangular

the solution is here :

http://classroomm.com/objective-c/index.php?topic=7490.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.