1.测试运行时间:
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { clock_t start,finish; double duration; start=clock(); /**/ //待测试时间的代码 finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("%lf seconds ",duration); return 0; }
2.生成随机数:
#include<stdlib.h> #include<stdio.h> #include<time.h> int main() { srand(unsigned(time(NULL))); for(int i=0;i<100;i++) printf("%d ",rand()%10); return 0; }