Skip to content

Instantly share code, notes, and snippets.

@WindAzure
Last active August 26, 2018 05:07
Show Gist options
  • Save WindAzure/24330d94533753fc2dd2841f6b669d88 to your computer and use it in GitHub Desktop.
Save WindAzure/24330d94533753fc2dd2841f6b669d88 to your computer and use it in GitHub Desktop.
algorithm exercise
#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;
printf("Case %d: %d", T++, a / b);
if (c == 0) { printf("\n"); continue; }
else { printf("."); }
auto remainderNum = a % b;
for (int i = 0; i < c - 1; i++)
{
remainderNum *= 10;
printf("%d", remainderNum / b);
remainderNum %= b;
}
auto tail = remainderNum * 100 / b + 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