Add a program that declares two arrays of 5 integers each. Provide one function to load one array with random numbers from 1 to 25, another to fill the other array with user supplied values, and a third function to print an array. The main function should declare the arrays and use the functions to fill each array and print them both.
The code i have so far is
#include <cstdlib>
#include <iostream>
using namespace std;
void printaaray(int printarray1[], int printarray2);
void printarray(int printarray1[], int printarray2)
{
for (int n = 0; n < printarray2; ++n)
cout << printarray1[n] << ' ';
cout << '\n';
}
void array(int firstarray[])
{
for (int i = 0; i < 25; ++i)(firstarray[i]) = (i + 1);
srand(firstarray[5]);
}
int main()
{
int firstarray[5];
int secondarray[5] = { 2, 4, 6, 8, 10 };
printarray(firstarray, 5);
printarray(secondarray, 5);
system("pause");
return 0;
}
#include <cstdlib>
#include <iostream>
#include <ctime>
usingnamespace std;
void printaaray(int printarray1[], int array_size);
void printarray(int printarray1[], int array_size)
{
for (int n = 0; n < array_size; ++n)
cout << printarray1[n] << ' ';
cout << '\n';
}
void fillarray(int firstarray[], int array_size)
{
//Set random generator seed
srand(time(0));
for (int i = 0; i < array_size; ++i){
//Fill each item with random generated number from 1 to 25 inclusive
firstarray[i] = rand() % 25 + 1;
}
}
int main()
{
int firstarray[5];
int secondarray[5] = { 2, 4, 6, 8, 10 };
//Fill array with random numbers
fillarray(firstarray, 5);
//Print first array
printarray(firstarray, 5);
//Print second array
printarray(secondarray, 5);
system("pause");
return 0;
}