#include
void main()
{
double a;
cin>>a;
cout<<"Change from 'a' ,'b'and 'c' that represent '2','8'and '16':"<<"\t";
char ch;
cin>>ch;
int aint=(int)a;
double aflo=a-aint;
switch(ch)
{
case 'a':
{
int i=0;
int b[20];
while(aint)
{
b[i]=aint%2;
aint/=2;
i++;
}
for(int temp=i-1; temp>=0;temp--)
cout< if(aflo)
{
cout<<".";
while(aflo)
{
b[i]=(int)(aflo*2);
cout< aflo=(aflo*2-(double)b[i]);
i++;
if(i>19)
break;
}
}
cout< }
case 'b':
{
int i=0;
int b[20];
while(aint)
{
b[i]=aint%8;
aint/=8;
i++;
}
for(int temp=i-1; temp>=0;temp--)
cout< if(aflo)
{
cout<<".";
while(aflo)
{
b[i]=(int)(aflo*8);
cout< aflo=(aflo*8-(double)b[i]);
i++;
if(i>19)
break;
}
}
cout< }
case 'c':
{
int i=0;
char b[20];
int j;
while(aint)
{
j=aint%16;
if(j<=9)
b[i]=j+'0';
else
b[i]=j-10+'A';
aint/=16;
i++;
}
for(int temp=i-1; temp>=0;temp--)
cout< if(aflo)
{
cout<<".";
while(aflo)
{
j=(int)(aflo*16);
if(j<=10)
{
b[i]=j+'0';
cout< }
else
{
b[i]=j-10+'A';
cout< }
aflo=(aflo*16-(double)j);
i++;
if(i>19)
break;
}
}
cout< }
}
}
--------------------next---------------------
阅读(1122) | 评论(0) | 转发(0) |