Please, Please instructed me

Hello C++ coders, couse i'm a absolute begginer i need a HELP with one task.

i need to write a function that recieves an array of integers, and number of elements, and return a quotient of the min anf max value of the array?

i dont have an idea how to solve this.....anyone can???...Please?...

thanks in advance
An array of integers looks like this: int array[50];
But since you're passing it to a function it will look like this: int *array;
A function looks like this: return_type name(formal_parameters)

So in the end, you function will look like:
1
2
int function(int *array, int size)
{}


Now inside the function you have to use a for() loop to find the maximum and minimum elements.

1
2
3
4
for (int i=0; i<size; ++i)
{
    /* figure it out */
}


Finally, return the quotient: return min/max;
Questions?
in the comment you put in the function /* figure it out*/ i have to find the max and the min value?...right?..but how should i do that...?...what's the way to do that?...Please?
Are we allowed to use the STL? Or are you being limited to generic arrays?
i think generic arrays ...can you help me with the code please?
The right way to do this would be to sort the array then return the quotient of the first and last elements in it. Do you know how to do that?
No i dont...can you help me?..i don't know sorting an arrays ..yet..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

int temp = 0;

for(int a = 0; a <= THE_SIZE_OF_YOUR_ARRAY; ++a)
{
     for(int b = 1; b <= THE_SIZE_OF_YOUR_ARRAY; ++b)
     {
            if(array[a] > array[b])
            {
                   temp = array[a];
                   array[a] = array[b];
                   array[b] = temp;
            }
       }
}


I left a bug or two in there so that you actually have to do some work. Don't panic and you should be able to figure it out on your own.
Last edited on
Topic archived. No new replies allowed.