Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- double dividef(int number, int arg, double& result, int currDig = 0) {
- if (currDig == 10)
- return result;
- else if (number % arg == 0 && number / arg == 0) {
- result += (number / arg) * (double)(pow(10, -1 * currDig));
- return result;
- }
- else {
- if (currDig)
- result += (number / arg) * (double)(pow(10, -1 * currDig));
- else
- result += number / arg;
- int nextNumber = (number % arg) * 10;
- return dividef(nextNumber, arg, result, currDig + 1);
- }
- }
- int main() {
- double result = 0;
- dividef(7, 19, result);
- printf("%.10f", result);
- }
Add Comment
Please, Sign In to add comment