#include <stdafx.h> #include <iostream> #include <cmath> // use the ctime library #include <ctime> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { // declare clock variables clock_t start,finish; double sum=0.; // start the clock ticking start = clock(); // do some calculations cout << "Starting calculation...\n"; for (int i=1; i<10000; i++) { for (int j=1; j<10000; j++) { sum += exp(-double(i)/(j)) + sin(0.1*j) + sqrt(double(i)/double(j)); } } // stop the clock finish = clock(); // print out time to screen. Note that finish and start must be converted to double, and then divided by CLOCKS_PER_SEC to convert into seconds cout << " Sum = " << sum << " and time taken for calculation is " << double(finish - start)/CLOCKS_PER_SEC << endl; system("pause"); return 0; }