fork(2) download
  1. #include <stdio.h>
  2.  
  3. int pow10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
  4.  
  5. int main(void) {
  6. int num = 12345;
  7. int n = 3;
  8.  
  9. int log10 = 0;
  10. while (pow10[log10] < num) {
  11. log10++;
  12. }
  13. int divisor = pow10[log10-n];
  14. int res = num / divisor;
  15. printf("log10(num)+1=%d, divisor=%d, result=%d\n", log10, divisor, res);
  16. return 0;
  17. }
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
log10(num)+1=5, divisor=100, result=123