Stoycho_KK

задача четвърта от първо контролно по УП КН

Jan 25th, 2021 (edited)
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. double dividef(int number, int arg, double& result, int currDig = 0) {
  5.     if (currDig == 10)
  6.         return result;
  7.     else if (number % arg == 0 && number / arg == 0) {
  8.         result += (number / arg) * (double)(pow(10, -1 * currDig));
  9.         return result;
  10.     }
  11.     else {
  12.         if (currDig)
  13.             result += (number / arg) * (double)(pow(10, -1 * currDig));
  14.         else
  15.             result += number / arg;
  16.  
  17.         int nextNumber = (number % arg) * 10;
  18.         return dividef(nextNumber, arg, result, currDig + 1);
  19.     }
  20.  
  21. }
  22.  
  23. int main() {
  24.     double result = 0;
  25.     dividef(7, 19, result);
  26.     printf("%.10f", result);
  27. }
Add Comment
Please, Sign In to add comment