Advertisement
paulogp

Capicua (v. 1.0.0)

Jul 13th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. // apple xcode
  2. // paulogp
  3.  
  4. /* numero que se le igualmente da direita para a esquerda ou vice-versa e
  5. ao qual se atribui boa sorte */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9.  
  10. #define MAX_INTERVAL 1000000
  11.  
  12.  
  13. int func_invert(int the_number) {
  14.     // inverte numero
  15.     int the_remainder;
  16.     int the_result;
  17.  
  18.     while (the_number != 0) {
  19.         the_remainder = the_number % 10;
  20.         the_number = the_number / 10;
  21.  
  22.         the_result = the_result * 10 + the_remainder;
  23.     }
  24.  
  25.     return the_result;
  26. }
  27.  
  28.  
  29. int main (int argc, const char * argv[]) {
  30.     // capicua
  31.     int the_number = 0;
  32.     int the_capicua = 0;
  33.  
  34.     // insert number
  35.     printf("numero: ");
  36.     scanf("%i", &the_number);
  37.  
  38.     // put some limits
  39.     if ((the_number >= -MAX_INTERVAL) && (the_number <= MAX_INTERVAL)) {
  40.         // invert
  41.         the_capicua = func_invert(the_number);
  42.         printf("numero: %i, invertido: %i\n", the_number, the_capicua);
  43.  
  44.         // capicua?
  45.         if (the_number == the_capicua) {
  46.             printf("capicua\n");
  47.         }
  48.     }
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement