|

楼主 |
发表于 2021-5-12 13:20:43
|
显示全部楼层
我能明白程序执行时间这个问题
但是我看明解C语言上的一个程序,打印的好像不是程序运行时间,而是用户操作用时?
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int stage;//已有数值
int a, b, c;
int x;
int n;
clock_t start, end;
srand(time(NULL));
printf("练习开始!!!!\n");
start = clock();
for (stage = 0; stage < 10; stage++) {
a = 10 + rand()%90;
b = 10 + rand()%90;
c = 10 + rand()%90;
n = rand()%17;
printf("%d%*s+%*s%d%*s+%*s%d:", a, n, "",n,"",b,n,"",n,"",c);
do{
scanf("%d", &x);
if(x == a+b+c){
break;
}
printf("\a回答错误!重新输入");
}while(1);
}
end = clock();
printf("start = %d, end = %d", start, end);
printf("用时%.1f秒.\n", (double)(end - start) / CLOCKS_PER_SEC);
return 0;
} |
|