Hello, Im fairly new with C++ and i was wondering you all may be able to help me with this programming question.
i need to generate N random numbers between 0 and 100 (inclusively) and store them in a dynamic integer array, as well as display the largest number of the data that was generated. i need to do this using the following function:
int max(int a[] , int n);
any help would be greatly appreciated as i have no idea how to approach this. thanks.]
this is what i have so far.
#include <iostream>
#include <string>
using namespace std;
//prototypes
int*gen(int n);
int main()
{
int n;
while (true)
{
cout << "Please enter an integer ";
cin >> n;
if (n==0) break;
int *a;
a = gen(n);
for (int i = 0; i < n; i++)
{
printf("%4d ", a[i]);
if ((i+1) % 4 == 0) cout << endl;
}
}
system("pause");
return 0;
}
int *gen(int n)
{
if (n <= 0) return 0;
int *tmp = new int[n];
for (int i = 0; i < n; i++)
{
tmp[i] = rand() % 101; //so remainder is 0-100
}
return tmp;
}