Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include <ctime>
  4. #include <chrono>
  5.  
  6. using namespace std;
  7. using namespace std::chrono;
  8.  
  9. bool IsPrime(int n){
  10. int i;
  11. bool isPrime = true;
  12. // cout << "Enter a positive integer: ";
  13. //cin >> n;
  14. for(i = 2; i <= n / 2; ++i)
  15. {
  16. if(n % i == 0)
  17. {
  18. isPrime = false;
  19. break;
  20. }
  21. }
  22. return isPrime;
  23. }
  24.  
  25. int main(){
  26.  
  27. high_resolution_clock::time_point t1 = high_resolution_clock::now();
  28. bool b1 = IsPrime(37);
  29. high_resolution_clock::time_point t2 = high_resolution_clock::now();
  30. auto duration = duration_cast<nanoseconds>( t2 - t1 ).count();
  31.  
  32. cout<<"time for IsPrime function is "<<duration<<" ns\n";
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement