Division.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. // Запрос ввода чисел у пользователя
  8. printf("Введите делимое: ");
  9. scanf("%lf", &dividend);
  10. printf("Введите делитель: ");
  11. scanf("%lf", &divisor);
  12. // Проверка деления на ноль
  13. if (divisor == 0) {
  14. printf("Ошибка: Деление на ноль!\n");
  15. return 1;
  16. }
  17. quotient = dividend / divisor;
  18. whole_part = (int)quotient; // целая часть
  19. fractional_part = quotient - whole_part; // дробная часть
  20. double count_0125_exact = fractional_part * 8;
  21. if (count_0125_exact - floor(count_0125_exact) < 0.5) {
  22. count_0125 = (int)floor(count_0125_exact);
  23. } else {
  24. count_0125 = (int)ceil(count_0125_exact);
  25. }
  26. printf("Целая часть: %d\n", whole_part);
  27. printf("Дробная часть: %lf\n", fractional_part);
  28. printf("Округленное количество единиц 0.125 в дробной части: %d\n", count_0125);
  29. return 0;
  30. }