baidu_34031378
baidu_34031378
2016-03-11 05:50
采纳率: 0%
浏览 1.5k

C语言关于随机数生成时间和与中间数的比较

#include
#include
#include

#define NCALLS 1000
#define NCOLS 8
#define NLINES 3

int main(void)
{
int i, val;
long begin, diff, end;
double median = RAND_MAX / 2, above_cnt=0, below_cnt=0, differences;

begin = time(NULL);
srand(time(NULL));
for (i = 1; i <=NCALLS; ++i) {
    val = rand();
    if (val < median) 
        below_cnt += 1;
    else if (val>median)
        above_cnt += 1;
    if (i <= NCOLS*NLINES) {
        printf("%7d", val);
        if (i%NCOLS == 0)
            printf("\n");
    }
    else if (i == NCOLS*NLINES + 1)
        printf("%7s\n\n", ".....");
}
end = time(NULL);
diff = end - begin;
differences = above_cnt - below_cnt;
printf("%s%ld\n%s%ld\n%s%ld\n%s%.10f\n%s%ld\n\n",
    "           end time:", end,
    "         begin time:", begin,
    "       elapsed time:", diff,
    " time for each call:", (double)diff / NCALLS,
    "        differences:",differences);

scanf_s("%d", &i);
return 0;

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • wen_wxpk
    找工作那些事 2016-03-11 06:27

    问题是啥?。。。。。。。。

    点赞 评论

相关推荐