### making a array

create an array of random numbers (7-14)
(not sorted)

use a for loop and find both the largest and smallest elements (integers).

hint:initialize the maxnum and minnum with the value of the first element in the array.

if ( maxnum < elelmentofarray)
{
// then update maxnum
}

i know how to make a array just need help with the rest
C++ already has algorithms to do this (you could use them to impress your professor).
http://www.cplusplus.com/reference/algorithm/min_element/
http://www.cplusplus.com/reference/algorithm/max_element/

Anyway, what you need to do is store the maximum element in maxnum, and minimum element in minnum.

 12345 int maxnum = array[0]; for (int i=0; i < size_of_array; ++i) if (maxnum < array[i]) maxnum = array[i];

 1234567891011121314151617181920212223242526272829 #include #include using namespace std; int main() { int random[5]; int biggest = 0; int smallest = 100; for(int i=0;i<5;i++) { random[i] = (rand()%7)+7; if(random[i]>biggest) biggest=random[i]; if(random[i]

You can change the array to however many rand numbers you want, given you also change the for loops. This is the basics of this.
Last edited on
Topic archived. No new replies allowed.