Amazon.com Widgets Program 13.5
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 25, 2014, 05:17:55 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
| |-+ Program Examples
| | |-+ Chapter 13
| | | |-+ Program 13.5
Pages: [1] Go Down
Print
Author Topic: Program 13.5 (Read 1468 times)
esc
Global Moderator
Full Member
*****
Posts: 230






on: March 01, 2009, 03:39:23 PM

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

// This function finds the greatest common divisor of two
// nonnegative integer values and returns the result

int gcd (int u, int v)
{
int temp;

while ( v != 0 )
{
temp = u % v;
u = v;
v = temp;
}

return u;
}

int main (int argc, char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int result;

result = gcd (150, 35);
NSLog (@"The gcd of 150 and 35 is %i", result);

result = gcd (1026, 405);
NSLog (@"The gcd of 1026 and 405 is %i", result);

NSLog (@"The gcd of 83 and 240 is %i", gcd (83, 240));
    [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.