Octal decimal Large data precise __c language

Source: Internet
Author: User

The problem is to convert the decimal to decimal decimals, the problem requirements, eight decimal point after the 15-bit drunk, so that the number of decimal in the most have 45, so directly do not work.
#include <iostream>
#include <string>
using namespace Std;
int main ()
{
int i,j,k;
String str;
while (CIN&GT;&GT;STR)//Enter octal decimal
{
K=str.size ();
int a[100]={0};
int index=0;
for (i=k-1;i>=2;i--)
{
int num=str[i]-' 0 ';
for (j=0;num!=0| | j<index;j++)//from the back to the decimal position out, so that each decimal multiplied by 10 and then add the above calculated to leave the number of decimal places to 8 modulo
{
num=10*num+ (j<index?a[j]:0); A[J] corresponds to the number of decimal places left in the previous step,
A[J]=NUM/8;
num=num%8;                                                                                      In 0.75, for example, 50+0 divided by 8 to get the a[0]=6,a[1]=2,a[2]=5, the second part of the loop, num=7, and then a[0]=7*10+6=9,a[1]=4*10+2=5,a[2]=2*10+5=3,a[3]=1*10+0=1,a[4]=2*10+0=2;a[5]=4*10+0=5;
The final output 0.A[0]A[1]A[2]A[3]A[4]A[5] is the decimal decimal number that is obtained. That is 0.953125
}
Index=j;
}
cout<<str<< "" << "[8] =" << "0.";
for (i=0;i<index;i++)
cout<<a[i];
cout<< "[A]" <<endl;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.