Advertisement
Ivan_Moscow

4.3.17.

Jun 2nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. void fillRandom (float* target, const unsigned int& length, const float& rmin, const float& rmax) {
  7.     for (int i=0; i<length; i++) {
  8.         target[i] = rmin + (float)rand()/RAND_MAX*(rmax-rmin);
  9.     }
  10. }
  11.  
  12.  
  13. int _tmain(int argc, _TCHAR* argv[]) {
  14.     srand(time(0));
  15.     unsigned int n;
  16.     cout << "Enter array length: ";
  17.     cin >> n;
  18.     float* numbers = new float[n];
  19.     float rmin, rmax;
  20.     cout << "Enter minimal and maximal random values: ";
  21.     cin >> rmin >> rmax;
  22.     fillRandom(numbers, n, rmin, rmax);
  23.     cout << "Result: " << endl;
  24.     for (int i=0; i<n; i++) {
  25.         cout << numbers[i] << endl;
  26.     }
  27.     delete[] numbers;
  28.     system("pause");
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement