Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2017, 11:40:36 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
|-+ Programming in Objective-C, 4th edition
| |-+ Chapter 13
| | |-+ Program 13.15-another way
Pages: [1] Go Down
Author Topic: Program 13.15-another way (Read 1792 times)
Posts: 24


WWW Email
on: June 07, 2012, 05:27:56 AM

I try to write the code of the program when I study a chapter, so I tried with chapter 13, and this is my version, in which you can pass the array to the function without saying which is the number of elements  Grin
Code: (Objective-C)

//  main.m
//  C-programming
//  Created by lori on 04/06/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.

#import <Foundation/Foundation.h>

int sum(int values[])
    int i = 0, result=0;
    while (values[i]!= '\0')
        result = values[i] + result;
    return result;

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

    @autoreleasepool {
        //sommo elementi di un array
#define ELEMENTS 15
        int values[ELEMENTS] = {1,3,2,4,5,2,6,5,2,3,4,2,4,1,5};
        int *valuesPtr = values;
        printf("This array has %i elements and their sum is = %i",ELEMENTS , sum(valuesPtr));

    return 0;


This array has 15 elements and their sum is = 49

"The more i know people the more i love dogs."Socrate

Posts: 1

Reply #1 on: January 25, 2017, 02:45:48 AM

Read the story here. It is knowledge that is very useful for me and for many people.


Pages: [1] Go Up
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.