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;

}

c

1个回答

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!