Guest User

Untitled

a guest
Apr 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. int n, i;
  2. bool flag = false;
  3.  
  4. cout << "Enter a positive integer: ";
  5. cin >> n;
  6.  
  7. for(i = 2; i <= n/2; ++i)
  8. {
  9. if (checkPrime(i))
  10. {
  11. if (checkPrime(n - i))
  12. {
  13. cout << n << " = " << i << " + " << n-i << endl;
  14. flag = true;
  15. }
  16. }
  17. }
  18.  
  19. if (!flag)
  20. cout << n << " can't be expressed as sum of two prime numbers.";
  21.  
  22. return 0;
  23.  
  24. bool isPrime = true;
  25.  
  26. for(i = 2; i <= n/2; ++i)
  27. {
  28. if(n % i == 0)
  29. {
  30. isPrime = false;
  31. break;
  32. }
  33. }
  34.  
  35. return isPrime;
Add Comment
Please, Sign In to add comment