fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int get10(double x)
  5. {
  6. return pow(10,floor(log10(x)));
  7. }
  8.  
  9. int main(int argc, const char * argv[])
  10. {
  11. for(int i = 1; i < 100000000; i*= 10)
  12. {
  13. printf("%10d: %10d\n",i-1,get10(i-1));
  14. printf("%10d: %10d\n",i,get10(i));
  15. }
  16. }
  17.  
Success #stdin #stdout 0s 4368KB
stdin
Standard input is empty
stdout
         0:           0
         1:           1
         9:           1
        10:          10
        99:          10
       100:         100
       999:         100
      1000:        1000
      9999:        1000
     10000:       10000
     99999:       10000
    100000:      100000
    999999:      100000
   1000000:     1000000
   9999999:     1000000
  10000000:    10000000