Advertisement
Farjana_akter

Untitled

Oct 10th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool isprime(int n)
  4. {
  5. int i;
  6. if(n<2)
  7. return false;
  8. for(i=2;i*i<=n;i++)
  9. {
  10. if(n%i==0){
  11. return false;
  12. }
  13. }
  14. return true;
  15. }
  16.  
  17. int main()
  18. {
  19. int flag=0,n,i,j,k;
  20. while(scanf("%d",&n)!=EOF)
  21. {
  22. if(n==1)
  23. {
  24. printf("%d is not the sum of two primes!\n",n);
  25. }
  26. else if(n%2==0)
  27. {
  28. flag=0;
  29. for(j=n/2-1;j>=2;j--)
  30. {
  31. if(isprime(j)==true && isprime(n-j)==true)
  32. {
  33. printf("%d is the sum of %d and %d.\n",n,j,n-j);
  34. flag=1;
  35. break;
  36. }
  37. }
  38. if(flag==0)
  39. printf("%d is not the sum of two primes!\n",n);
  40. }
  41. else
  42. {
  43. if(isprime(n-2)==true)
  44. printf("%d is the sum of 2 and %d.\n",n,n-2);
  45. else
  46. printf("%d is not the sum of two primes!\n",n);
  47. }
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement