fork download
  1. #include <stdio.h>
  2. #include <cmath>
  3.  
  4. int countOfBits(int number) {
  5.  
  6. int counter = 0;
  7.  
  8. while (number != 0) {
  9.  
  10. ++counter;
  11.  
  12. number /= 10;
  13. }
  14.  
  15. return counter;
  16. }
  17.  
  18. bool numberPalindrome(int number, int toBase) {
  19.  
  20. int size = countOfBits(number);
  21.  
  22. int mid = size / 2;
  23.  
  24. for (int i = 0; i != mid; ++i) {
  25.  
  26. int leftBit = std::pow(toBase, size - i + 1);
  27.  
  28. int rightBit = number % std::pow(toBase, i + 1);
  29.  
  30. printf("%d %d\n", leftBit, rightBit);
  31. }
  32.  
  33. }
  34.  
  35. int main() {
  36.  
  37. int number;
  38.  
  39. scanf("%d", &number);
  40.  
  41.  
  42.  
  43. // for (int i = 0; i != 35; ++i) {
  44.  
  45. // numberPalindrome(number, i + 2);
  46. // }
  47.  
  48. numberPalindrome(number, 10);
  49.  
  50. return 0;
  51. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
102892748
compilation info
prog.cpp: In function ‘bool numberPalindrome(int, int)’:
prog.cpp:28:25: error: invalid operands of types ‘int’ and ‘__gnu_cxx::__promote_2<int, int, double, double>::__type’ {aka ‘double’} to binary ‘operator%’
   int rightBit = number % std::pow(toBase, i + 1);
                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:33:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
prog.cpp: In function ‘int main()’:
prog.cpp:39:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &number);
  ~~~~~^~~~~~~~~~~~~~~
stdout
Standard output is empty