Amazon.com Widgets Exercise 1, Chapter 5 - User Input
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 05:41:15 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
| |-+  Answers to Exercises
| | |-+  Chapter 5
| | | |-+  Exercise 1, Chapter 5 - User Input
Pages: [1]   Go Down
Print
Author Topic: Exercise 1, Chapter 5 - User Input  (Read 241 times)
Devalin
Newbie
*
Posts: 3






« on: June 29, 2012, 09:32:43 AM »

Hello fellow programmers Smiley !

I want to share with you my solution to Exercise 1, Ch.5:
Code: (Objective-C)
#import <Foundation/Foundation.h>

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

    @autoreleasepool
    {
        
        int number, maxCount, squaredNumber;
                    
        
        NSLog(@"What Range of Squared Numbers Do You Want - Starting from 1 - ?");
        scanf("%i", &number);
        maxCount = number;
        
        NSLog(@"TABLE OF SQUARED NUMBERS");
        NSLog(@"Number Squared Number");
        NSLog(@"------ --------------");
        
        for (int count = 1, number = 1; count <= maxCount; ++count, ++number)
        {
            squaredNumber = pow(number, 2);
            NSLog(@"  %2i %10i",number, squaredNumber);
        }
    }
    return 0;
}

OUTPUT:
Quote
What Range of Squared Numbers Do You Want - Starting from 1 - ?
 14
 TABLE OF SQUARED NUMBERS
 Number Squared Number
 ------ --------------
    1          1
    2          4
    3          9
    4         16
    5         25
    6         36
    7         49
    8         64
    9         81
   10        100
   11        121
   12        144
   13        169
   14        196
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.