基于visual Studio2013解决面试题之1310随机数

来源:互联网 发布:移动网络监控怎么收费 编辑:程序博客网 时间:2024/05/07 01:00



题目



解决代码及点评

/*设 rand (s,t)返回[s,t]之间的随机小数,利用该函数在一个半径为 R 的圆内找随机 n 个点,并给出时间复杂度分析。*/#include <iostream>#include <time.h>#include <math.h>using namespace std;void GetNPointInCircle(int R, int n){    srand(time(NULL));    for (int i = 0; i < n; i++)    {        double dblx = rand()%(2 * R + 1) - R;        int dblTmp = sqrt(R*R - dblx * dblx);        double dbly = rand()%(2 * dblTmp + 1) - dblTmp;        cout<<"x="<<dblx<<",y="<<dbly<<endl;    }}int main(){    GetNPointInCircle(4, 100);                                                                                            system("pause");    return 0;}


代码下载及其运行

代码下载地址:http://download.csdn.net/detail/yincheng01/6704519

解压密码:c.itcast.cn


下载代码并解压后,用VC2013打开interview.sln,并设置对应的启动项目后,点击运行即可,具体步骤如下:

1)设置启动项目:右键点击解决方案,在弹出菜单中选择“设置启动项目”


2)在下拉框中选择相应项目,项目名和博客编号一致

3)点击“本地Windows调试器”运行


程序运行结果








0 0
原创粉丝点击