I am new to arrays and need some help with making an array that prints out 25 random numbers between 3 to 7, using simple functions. I have the array set up, but I am stuck on how to make the loop portion I think. I have also created the function prototypes/definitions that I want to use to return the answers. Here is an example of what I am going for.
Making an array of 25 random integers from 3 to 7!
Original array a [ ] = { 3, 7, 5, 6, 3, 4, 4, 3, 5, 5, 6, 5, 5, 7, 3, 5, 3, 6, 4, 5, 7, 4, 7, 3, 5 }
Reversed array a [ ] = { 5, 3, 7, 4, 7, 5, 4, 6, 3, 5, 3, 7, 5, 5, 6, 5, 5, 3, 4, 4, 3, 6, 5, 7, 3 }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <time.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
void showArray ( int a[ ], int size ); // shows the array in the format "int a [ ] = { 3, 7, 4, ... ,5, 6, 3, 4, 7 } "
void showReverse ( int a[ ], int size ); // shows the array in reverse using the format "int a [ ] = { 7, 4, 3, 6, 5, ... , 4, 7, 3 } "
int main ()
{
srand((int)time(NULL));
int i=0;
float randvalue[4000];
randvalue[i] = rand () % 3 + 5; // random number between 3 to 7
cout << "Making an array of 25 random integers from 3 to 7!" << endl;
cout<<"Original array a [ ] = " <<randvalue[i] << endl;
// Reversed array
randvalue[i] = rand () % 3 + 5;
cout<<"Reversed array a [ ] = " <<randvalue[i];
return 0;
}
// Function definitions
void showArray ( int a[ ], int size )
void showReverse ( int a[ ], int size )
|