Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- // function prototype
- void printData(int [], int);
- int main ()
- {
- // size for array
- const int ARRAY_SIZE = 5;
- srand(time(0)); // seed random number
- int Numbers [ARRAY_SIZE] = {-10,-6,0,3,10};
- //generate random index number
- for (int i=0; i < ARRAY_SIZE; i++)
- {
- int index = rand() % ARRAY_SIZE;
- //using temporary varibles as random algorithm to switch it around
- int temp = Numbers[i];
- Numbers[i] = Numbers[index];
- Numbers[index] = temp;
- }
- // function
- printData(Numbers, ARRAY_SIZE);
- return 0;
- }
- // function end
- //***************
- //* function for printing the data
- //*
- //***************
- void printData(int Numbers[], int size)
- {
- // loop through array and print values
- for (int i=0; i < 1; i++)
- {
- cout << "Element 1 of the array is: " << Numbers[0] << endl;
- cout << "Element 2 of the array is: " << Numbers[1] << endl;
- cout << "Element 3 of the array is: " << Numbers[2] << endl;
- cout << "Element 4 of the array is: " << Numbers[3] << endl;
- cout << "Element 5 of the array is: " << Numbers[4] << endl;
- }
- }
- // function end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement