标签【vector学习】:2022年4月12日 22:32:35

阅读 25

2022-04-14

#include <stdlib.h> // rand(), srand()
#include <stdio.h> // printf()
#include<Windows.h> 
#include <iostream>
using namespace std;

void RangedRandDemo(int range_min, int range_max, int n,int ts[1])
{
	DWORD start_time = GetTickCount(); 
	for (int i = 0; i < n; i++)
	{
		int r = ((double)rand() / RAND_MAX) * (range_max - range_min) + range_min;
		printf("  %6d\n", r);
	}
	DWORD end_time = GetTickCount();
	ts[0]=(end_time - start_time);
}
int main(void)
{	
	int ts[1];
	RangedRandDemo(-100, 100, 500, ts);
	cout << "The run time is:" <<ts[0]<< "ms!" << endl; 
	system("pause");
}

精彩评论(0)

0 0 举报