Division.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main() {
  4. double dividend, divisor;
  5. double quotient, fractional_part;
  6. int whole_part, count_0125;
  7. printf("Введите делимое: ");
  8. scanf("%lf", &dividend);
  9. printf("Введите делитель: ");
  10. scanf("%lf", &divisor);
  11. if (divisor == 0) {
  12. printf("Ошибка: Деление на ноль!\n");
  13. return 1;
  14. }
  15. quotient = dividend / divisor;
  16. whole_part = (int)quotient; // целая часть
  17. fractional_part = quotient - whole_part; // дробная часть
  18. double count_0125_exact = fractional_part * 8;
  19. if (count_0125_exact - floor(count_0125_exact) < 0.5) {
  20. count_0125 = (int)floor(count_0125_exact);
  21. } else {
  22. count_0125 = (int)ceil(count_0125_exact);
  23. }
  24. printf("Целая часть: %d\n", whole_part);
  25. printf("Дробная часть: %lf\n", fractional_part);
  26. printf("Округленное количество единиц 0.125 в дробной части: %d\n", count_0125);
  27. return 0;
  28. }