爲了測試的方便,有時需要隨機生成n個整數,代碼如下:
#include<iostream> #include<stdlib.h> #include<vector> #include<time.h> #include<iomanip> using namespace std; /////////////////////////////////////////// /* **函數名: randomGenerated **功能: 隨機生成n個整數 **參數: int arr_size:隨機生成的整數個數 **返回值: vector<int> */ vector<int> randomGenerated(int arr_size,int range) { vector<int> vec; time_t t; srand(time(&t)); for(int i = 0; i < arr_size; i++) { vec.push_back(rand()%range); //隨機生成的整數範圍在0~range範圍內 } return vec; } /////////////////////////////////////////// int main() { int count; //隨機生成的整數個數 int range; //隨機生成的整數最大值(範圍上限) vector<int> arr; cout << "Input the count of the number: " << endl; cin >> count; cout << "Input the max value of the random number: " << endl; cin >> range; arr = randomGenerated(count,range); for(int j = 0; j < count; j++) { cout << setw(5) << arr[j]; } cout << endl; return 0; }
{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image"
{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"typ
{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockq
{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragr
{"type":"doc","content":[{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null
{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"爲什麼TDD很重要"
直播簡介 在這快速變化的時代,無論是何種規模的企業都在關注看重效能,研發效能的變革是許多 IT 公司首先要考慮的,例如研效平臺建設、度量體系建設、數據驅動管理等。藉助新技術、新工具等全面提升軟件工程效能。要達到 10 倍效能,需要利用一切可
{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"前言"}]},{"t
{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"前言","attrs