Advertisement
Guest User

Untitled

a guest
May 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. bool patrat_perfect(int x)
  8.  
  9. {
  10.  
  11.     if(sqrt(x)==(int)sqrt(x))
  12.  
  13.         return true;
  14.  
  15.     return false;
  16.  
  17. }
  18.  
  19. int main()
  20.  
  21. {
  22.  
  23.     int v[200];
  24.  
  25.     int n;
  26.  
  27.     cout<<"n=";
  28.  
  29.     cin>>n;
  30.  
  31.     for(int i=0; i<n; i++)
  32.  
  33.     {
  34.  
  35.         cout<<"v["<<i<<"]=";
  36.  
  37.         cin>>v[i];
  38.  
  39.     }
  40.  
  41.     cout<<"Sirul initial: ";
  42.  
  43.     for(int i=0; i<n; i++)
  44.  
  45.         cout<<v[i]<<" ";
  46.  
  47.     cout<<endl;
  48.  
  49.     int i=0;
  50.  
  51.     while(i<n)
  52.  
  53.     {
  54.  
  55.         if(patrat_perfect(v[i]))
  56.  
  57.         {
  58.  
  59.             for(int j=n; j>i; j--)
  60.  
  61.                 v[j]=v[j-1];
  62.  
  63.             v[i]=(int)sqrt(v[i]);
  64.  
  65.             n++;
  66.  
  67.             i=i+2;
  68.  
  69.         }
  70.  
  71.         else
  72.  
  73.             i++;
  74.  
  75.     }
  76.  
  77.     cout<<"Sirul final: ";
  78.  
  79.     for(int i=0; i<n; i++)
  80.  
  81.         cout<<v[i]<<" ";
  82.  
  83.     return 0;
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement