include <stdio.h>
#include <string.h>
#define maxn 100
#define display_limit 50
#define max_INT 10000
int main(){
int digits[max_INT];
int reminder[max_INT];
int ori_numerator,numerator,denominator,quotient;//分子,分母,商
while(scanf("%d%d", &numerator, &denominator) != EOF && denominator){
memset(reminder, 0, sizeof(reminder));
memset(digits, 0, sizeof(digits));
int begin,circle,i,repetition;
int flag=0;
ori_numerator=numerator;
for(i=0;i<max_INT;i++){
digits[i]=numerator/denominator;
numerator=numerator-digits[i]*denominator;
reminder[i]=numerator;
numerator*=10;
for(circle=0;circle<i;circle++){
if (reminder[circle]==reminder[i])
{
begin=circle;
repetition=i-circle;
flag=1;
break;
}
}
if (flag)
{
break;
}
}
//output
printf("%d/%d = %d.",ori_numerator,denominator,digits[0]);
for(i=1;i<=begin;i++)
printf("%d",digits[i]);
printf("(");
if(repetition>display_limit)
{
for(i=0;i<display_limit;i++){
printf("%d",digits[begin+1]);
begin++;
}
printf("...)\n");
}
else{
for(i=0;i<repetition;i++){
printf("%d",digits[begin+1]);
begin++;
}
printf(")\n");
}
printf(" %d = number of digits in repeating cycle\n\n", repetition);
}
return 0;
}
Uva202
最新推荐文章于 2022-03-17 20:43:35 发布