在C++中一些小问题

来源:互联网 发布:网络犯罪罪名 编辑:程序博客网 时间:2024/05/01 21:02

1.记录程序运行时间

<span style="font-size:18px;">#include "time.h"using namespace std;int main(){    clock_t start, finish;    double time_length;    start = clock();//start存储的是当前的时刻   .......................    finish = clock();//finish存储的是结束的时刻    time_length = (double)(finish - start) / CLOCKS_PER_SEC;//根据两个时刻的差,计算出运行的时间    cout<<"Time used is "<<time_length<<" second."<<endl;       return 0;}</span>



CLOCKS_PER_SEC:是为了把时间转换为秒 :  C++中   #define CLOCKS_PER_SEC  1000


2.计算x的y次方
<span style="font-size:18px;">#include <iostream.h>#include <math.h>//记得包含void main(){ int n,m;.................m=pow(x,y);.....}</span>

未完待续



0 0