Advertisement
Josif_tepe

Untitled

Nov 14th, 2023
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int rek(int x) {
  4.     if(x == 0) {
  5.         return 0;
  6.     }
  7.     int cifra = x % 10;
  8.     if(cifra <= 4) {
  9.         cifra++;
  10.     }
  11.     else {
  12.         cifra--;
  13.     }
  14.     return rek(x / 10) * 10 + cifra;
  15. }
  16. int main () {
  17.  
  18.     int n;
  19.     scanf("%d", &n);
  20.     printf("%d\n", rek(n));
  21.  
  22. return 0;
  23.  
  24. }
  25. // rek(123456) = rek(12345) * 10 + 5 = 23454 * 10 + 5 = 234545
  26. // rek(12345) = rek(1234) * 10 + 4 = 2345 * 10 + 4 = 23454
  27. // rek(1234) = rek(123) * 10 + 5 = 234 * 10 + 5 = 2345
  28. // rek(123) = rek(12) * 10 + 4 = 23 * 10 + 4 = 234
  29. // rek(12) = rek(1) * 10 + 3 = 2 * 10 + 3 = 23
  30. // rek(1) = rek(0) * 10 + 2 = 2
  31. // rek(0) = 0
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement