Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
August 18, 2017, 09:32:57 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Program 13.15-another way  (Read 1995 times)
eagle74
Newbie
*
Posts: 24


www.cucinareblog.it


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

hello!!
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;
        i++;
    }
  
    
    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;
    }
}



OUTPUT:

This array has 15 elements and their sum is = 49
Logged

"The more i know people the more i love dogs."Socrate
Jamepoison
Newbie
*
Posts: 1


Email
« 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.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.