c programming help(functions)

This is a discussion on c programming help(functions) within the C Programming forums, part of the General Programming Boards category; hi, I'm trying to write a functions that return the following value. (Assume that a and n are parameters, where ...

  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 abson6@aol.com

  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,796
    >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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21