Advertisement
STANAANDREY

T14/01/2019 ex2

Jan 14th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.  unsigned n,x,eprim,dif,d,difepr;
  9. do {
  10.         cout<<"nr sa fie par:"<<endl;
  11.  cout<<"n=";cin>>n;
  12. }while (n%2!=0);
  13.  
  14.   for (x=3;x<=n/2;x+=2)
  15.   {
  16.       eprim=1;d=2;
  17.      while (d<=sqrt(x))
  18.      {
  19.          if (x%d==0)
  20.           eprim=0;
  21.          d++;
  22.      }
  23.        if (eprim)
  24.   {
  25.       dif=n-x;
  26.       difepr=1;
  27.       for (d=2;d<=dif/2;d++)
  28.         if (dif%d==0)
  29.          difepr=0;
  30.  
  31.          if (difepr) {
  32.             cout<<"nr poate fi scris ca "<<x<<'+'<<dif<<endl;
  33.             //break;
  34.              }
  35.     }
  36.   }
  37.  return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement