fork download
  1. #include <stdio.h>
  2.  
  3. void sep_if(int val, char *sdec)
  4. {
  5. int ip, tp, hp;
  6. int sgn = 0;
  7.  
  8. if (val < 0)
  9. {
  10. sgn = 1;
  11. val = -val;
  12. }
  13.  
  14. ip = val / 100;
  15. tp = (val - ip * 100) / 10;
  16. hp = val - ip * 100 - tp * 10;
  17.  
  18. if (sgn)
  19. sprintf(sdec, "-%d.%1d%1d", ip, tp, hp);
  20. else
  21. sprintf(sdec, "%d.%1d%1d", ip, tp, hp);
  22. }
  23.  
  24. int main(void)
  25. {
  26. int value;
  27. char dval[12];
  28.  
  29. value = 13901;
  30. sep_if(value, dval);
  31. printf("%d => %s\n", value, dval);
  32.  
  33. value = -101;
  34. sep_if(value, dval);
  35. printf("%d => %s\n", value, dval);
  36.  
  37. value = 7;
  38. sep_if(value, dval);
  39. printf("%d => %s\n", value, dval);
  40.  
  41. value = -8;
  42. sep_if(value, dval);
  43. printf("%d => %s\n", value, dval);
  44.  
  45. value = 23;
  46. sep_if(value, dval);
  47. printf("%d => %s\n", value, dval);
  48.  
  49. value = 555555;
  50. sep_if(value, dval);
  51. printf("%d => %s\n", value, dval);
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
13901 => 139.01
-101 => -1.01
7 => 0.07
-8 => -0.08
23 => 0.23
555555 => 5555.55