Advertisement
Guest User

Numar ca suma a doua numere prime

a guest
Dec 5th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int n;
  4. int main()
  5. {
  6.     cout<<"Introduceti numarul pe care vreti sa il scrieti ca suma a doua numere prime: "; cin >> n;
  7.     for (int i = 2;i <= n/2; i++)
  8.     {
  9.         int d;
  10.         int nr = 0;
  11.         for (d = 2; d <= i/2; d++)
  12.         {
  13.             if ( i % d == 0)
  14.                 nr++;
  15.         }
  16.  
  17.         if (nr == 0)
  18.         {
  19.             int e = n - i;
  20.             int j;
  21.             int nr2 = 0;
  22.             for(j = 2; j <= e/2; j++)
  23.             {
  24.                 if(e % j == 0)
  25.                     nr2++;
  26.  
  27.             }
  28.             if(nr2 == 0)
  29.             {
  30.                 cout << i << " + "<< e <<endl;
  31.  
  32.             }
  33.  
  34.  
  35.         }
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement