Thread: c programming help(functions)

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    1

    c programming help(functions)

    hi,
    I'm trying to write a functions that return the following value. (Assume that a and n are parameters, where a is an array of int values and n is the lenght of the array.)

    (a) The largest element in a.
    (b) The average of all elements in a.
    (c) The number of positive elements in a.






    please help
    e-mail [email protected]

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273

    sounds like homework

    not giving code but I'll say something about each

    a - loop through all elements, continually check the value against the max

    b- loop through all elements, add up the values and divide by n at the end

    c- loop through all elements, increment a counter when you come across a value that is > 0

    function prototypes:

    int Largest(int *a, int n);
    int Average(int *a, int n);
    int NumPos(int *a, int n);

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm trying to write a functions that return the following value.
    Okay, what have you come up with so far?

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed