Advertisement
Guest User

Var10 sub3 ex3

a guest
Mar 30th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void sub(unsigned int n,unsigned int &a, unsigned int &b)
  6. {
  7.     unsigned int cnt=2;
  8.     for(int i=n;i>=2 && cnt;i--)
  9.     {   int x=0;
  10.         for(int j=2;j<i/2;j++)
  11.         {
  12.             if(!(i%j))
  13.                 x++;
  14.         }
  15.         if(!x)
  16.         {
  17.             cnt--;
  18.             if(cnt == 1)
  19.                 a=i;
  20.             else if(cnt == 0)
  21.                 b=i;
  22.         }
  23.     }
  24. }
  25.  
  26. int main()
  27. {
  28.     unsigned int n,a=0,b=0;
  29.     cin>>n;
  30.     sub(n,a,b);
  31.     cout<<a<<" "<<b;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement