csansoon

P6.06 P57515 P0019. Rotacions cap a la dreta

Nov 7th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int rotacio_dreta(int x, int k) {
  6.     int digits=0;
  7.     for (int x2=x;x2>0;x2=x2/10) digits++;
  8.     for (k; k>0; k--) {
  9.         int lastdig=x%10;
  10.         x=x/10;
  11.         x=x+(lastdig*pow(10,(digits-1)));
  12.     }
  13.     return x;
  14. }
  15. int main() {
  16.     int number,rotations;
  17.     while(cin>>number>>rotations) cout<<rotacio_dreta(number,rotations)<<endl;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment