傻源源吧 关注:3贴子:392
  • 0回复贴,共1

计概代码临时存储

只看楼主收藏回复

#include<stdio.h>
#include<math.h>
double bjz (char x[])
{
double d=0;
int i;
double q=0.125;
for (i=2;x[i]!='\0';i++)
{
d=d+(x[i]-'0')*q;
q=q/8;
}
printf("%lf ",d);
return d;
}
int main()
{
double sum=0;
double d,c;
double q=0.1;
int i;
char octal[100];
char sjz[100];
while (scanf("%s",octal)!=EOF)
{
d=bjz(octal);
sum=0;
sjz[0]='\0';
c=d;
for (i=0;c-sum>0;i++)
{
d=d*10;
sjz[i]=((int)d)%10+'0';
sum=sum+q*(sjz[i]-'0');
q=q/10;
}
sjz[i]='\0';
printf("%s [8] = 0.%s [10]\n",octal,sjz);
}
return 0;
}


IP属地:北京1楼2016-12-09 19:36回复