Advertisement
icatalin

Problema 7 tema suplimentara

Nov 27th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. //7.    Să se afișeze toate numerele prime mai mici sau egale cu n, care citite invers, sunt tot numere prime.
  2.  
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int n,cpn,cpnB,numarprim,i,i2,OK,OKP,ogl=0,uc;
  12.     cout<<"n="<<endl;
  13.     cin>>n;
  14.     for (n;n>1;n--)
  15.         {
  16.         cpn=n;
  17.         cpnB=n;
  18.         numarprim=n;
  19.         OK=1;
  20.         OKP=1;
  21.         for (i=2;i<=sqrt(cpn);i++)
  22.         {
  23.             if (cpn%i==0)
  24.             OK=0;
  25.         }
  26.  
  27.  
  28.         while (cpnB)
  29.         {
  30.            uc=cpnB%10;
  31.         cpnB=cpnB/10;
  32.             ogl=ogl*10+uc;
  33.         }
  34.         for (i2=2;i<=sqrt(ogl);i++)
  35.         {
  36.             if(ogl%i2==0)
  37.             OKP=1;
  38.         }
  39.  
  40.         if (OK==1 && OKP==1)
  41.  
  42.         cout<<numarprim<<endl;
  43.  
  44.     }
  45.  
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement