Last active
August 26, 2018 05:07
-
-
Save WindAzure/e16fd6aafa339117a8c0cf3cf8f2e883 to your computer and use it in GitHub Desktop.
algorithm exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int main() | |
{ | |
auto T = 1; | |
auto a = 0, b = 0, c = 0; | |
while (~scanf("%d%d%d", &a, &b, &c)) | |
{ | |
if (a == 0 && b == 0 && c == 0) break; | |
auto quotient = static_cast<double>(a) / b; | |
auto intPart = static_cast<int>(floor(quotient)); | |
quotient -= intPart; | |
printf("Case %d: %d", T++, intPart); | |
if (c == 0) { printf("\n"); continue; } | |
else { printf("."); } | |
for (int i = 0; i < c - 1; i++) | |
{ | |
quotient *= 10; | |
auto singleDigit = static_cast<int>(floor(quotient)); | |
printf("%d", singleDigit); | |
quotient -= singleDigit; | |
} | |
auto tail = static_cast<int>(floor(quotient * 100)) + 5; | |
printf("%d\n", tail / 10); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment