Amazon.com Widgets 6.10 from the book
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 02, 2014, 11:49:17 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
|-+  Old Stuff
| |-+  Program Examples
| | |-+  Chapter 6
| | | |-+  6.10 from the book
Pages: [1]   Go Down
Print
Author Topic: 6.10 from the book  (Read 1211 times)
mtube
Newbie
*
Posts: 14


Email




« on: May 06, 2010, 08:46:09 PM »

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

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int p, isPrime, d;

p = 2;

while (p <= 50){
isPrime = 1;
++p;
for (d = 2; d< p; ++d)
if ( p% d == 0 )
isPrime = 0;
if (isPrime != 0)
NSLog (@"%i", p);
}

    // insert code here...
    //NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}
run
[Switching to process 4489]
Running…
2010-05-06 23:43:03.299 6.10[4489:80f] 3
2010-05-06 23:43:03.303 6.10[4489:80f] 5
2010-05-06 23:43:03.304 6.10[4489:80f] 7
2010-05-06 23:43:03.305 6.10[4489:80f] 11
2010-05-06 23:43:03.306 6.10[4489:80f] 13
2010-05-06 23:43:03.307 6.10[4489:80f] 17
2010-05-06 23:43:03.309 6.10[4489:80f] 19
2010-05-06 23:43:03.310 6.10[4489:80f] 23
2010-05-06 23:43:03.311 6.10[4489:80f] 29
2010-05-06 23:43:03.312 6.10[4489:80f] 31
2010-05-06 23:43:03.312 6.10[4489:80f] 37
2010-05-06 23:43:03.315 6.10[4489:80f] 41
2010-05-06 23:43:03.316 6.10[4489:80f] 43
2010-05-06 23:43:03.316 6.10[4489:80f] 47

Debugger stopped.
Program exited with status value:0.

I was playing around with the prgm in the book. why doesn't  the number 2 show what did i do wrong in the while construct?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







« Reply #1 on: May 07, 2010, 02:36:39 AM »

This is a modified version of 6.10. You need to look at where you're incrementing p.

Cheers,

Steve Kochan 
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.