Advertisement
icatalin

varianta 3 subiectul III exercitul 2 neterminat

Oct 29th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  
  6. int s1(int n)
  7. {
  8.     int c=0;
  9.     while (n)
  10.     {
  11.         n=n/10;
  12.         c++;
  13.     }
  14.     return c;
  15. }
  16.  
  17.  
  18.  
  19. int s2(int k)
  20. {
  21.     int q,i,nr2,nou,cif,zece;
  22.     cout<<"q= ";cin>>q;
  23.     int cop;
  24.     cop=q;
  25.  
  26. while (cop)
  27.         for (i=1;i<=s1(q);i++)
  28.     {
  29.         zece=pow(10,i);
  30.         if (cop%10==k)
  31.         {
  32.         nr2=cop%zece;
  33.         cop=cop/zece;
  34.         cop=cop*10+cop%10;
  35.         cop=cop*zece+nr2;
  36.         nou=cop;
  37.         }
  38.         cop=cop/10;
  39.     }
  40.     cout<<nou;
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. int main()
  50. {
  51.  s2(2);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement