If i had an Array as seen below, is it possible to use the rand function to randomly select an element within that particular array; if so how can this be done. The Value of the element will be outputted.

Any help much appreciated...:)

int Array[14]={10,10,10,10,11,6,9,2,3,15,11,15,16,15};

#include <iostream>
#include <cstdlib>
#include <math.h>
#include <time.h>
using namespace std;
void seed(){
srand(time(0));
}
double Randunif(){
return rand() / double(RAND_MAX);
}
double Randunif(double x){
return ((Randunif()*x)+1);
}
int main() {
seed();
r=Randunif(14); //---->14 is size of array (check if value is 14, decrement by 1 since array indexing is 0-based in C++)
cout << floor(r); // to see which index of array will be chosen
cout << Array[r];
return 0;
}

That wasn't my solution, so I'll let Aranarth answer, but I can suggest that if you use an std::vector<int> instead of an array the syntax gets much lighter - that is yourArray.size() vs sizeof(yourArray)/sizeof(*yourArray)

That wasn't my solution, so I'll let Aranarth answer, but I can suggest that if you use an std::vector<int> instead of an array the syntax gets much lighter - that is yourArray.size() vs sizeof(yourArray)/sizeof(*yourArray)

cool, but how exactly would i list all the elements within if i were to use a Vector. For intance with an array it would be:

int Array[]={1,2,6,7,8,89};

but how would this be applied when using a Vector....:)

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...