Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include <ctime>
- #include <chrono>
- using namespace std;
- using namespace std::chrono;
- bool IsPrime(int n){
- int i;
- bool isPrime = true;
- // cout << "Enter a positive integer: ";
- //cin >> n;
- for(i = 2; i <= n / 2; ++i)
- {
- if(n % i == 0)
- {
- isPrime = false;
- break;
- }
- }
- return isPrime;
- }
- int main(){
- high_resolution_clock::time_point t1 = high_resolution_clock::now();
- bool b1 = IsPrime(37);
- high_resolution_clock::time_point t2 = high_resolution_clock::now();
- auto duration = duration_cast<nanoseconds>( t2 - t1 ).count();
- cout<<"time for IsPrime function is "<<duration<<" ns\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement