#include <cstdlib> #include <iostream> #include <cmath> // use the ctime library #include <ctime> using namespace std; int main() { // declare clock variables clock_t start,finish; // start the clock ticking start = clock(); // start doing some calculations cout << "Starting calculation...\n"; double sum=0.; 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)); } } // finished calculations // 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; return 0; }