Arguments

Hey guys, I have a program here that generates a random array of 10 numbers. My problem is I'm supposed to add a function that accepts an int array and the array's size as arguments. This function should create a new array that is one element larger than the argument array. I am new to C++ and could use any help!


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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
void format();
void print_array(int[],const int);

int main()
{
	const int arraysize = 10;
	int num_arr[arraysize] = {0};
	srand(unsigned(time(0)));

	for(int index=0;index < arraysize;index++)
		num_arr[index] = rand() % 100 + 1;

	print_array(num_arr,arraysize);


return 0;
}
void print_array(int n[], const int s)
{
	for(int i=0;i<s;i++)
		cout << n[i] << " ";
	cout << endl;
}
Topic archived. No new replies allowed.