Idanref

ex 4

Nov 25th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void encrypt(int num)
  5. {
  6.     int length = -1;
  7.     int num_copy = num; // a number to measure the length
  8.     int num_left_to_right;
  9.     int current_num;
  10.  
  11.     while(num_copy != 0)
  12.     {
  13.         length++;
  14.         num_copy /= 10;
  15.     }
  16.  
  17.     while(length > -1)
  18.     {
  19.         num_left_to_right = num * pow(10, (-1) * (length));
  20.         current_num = num_left_to_right % 10;
  21.  
  22.         if(current_num ==  0)
  23.             current_num = 8;
  24.        
  25.         else if(current_num == 1)
  26.             current_num = 9;
  27.  
  28.         else
  29.             current_num -= 2;
  30.        
  31.         printf("%d", current_num);
  32.         length--;
  33.     }
  34. }
  35.  
  36.  
  37. void main()
  38. {
  39.     encrypt(12034);
  40. }
Add Comment
Please, Sign In to add comment