View Code of Problem 258

#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<cstdio>
using namespace std;
int main()
{
	char s[30];
	while (scanf("%s", s) != EOF)
	{
		int len = strlen(s);
		long  double sum = 0;
		//int cnt = len - 2;
		int j;
		for (j = 0;j < len;j++)
		{
			if (s[j] == '.')
			{
				break;
			}
		}
		int cnt = 1;
		for (int i = j+1;i < len;i++)
		{
			long double z = pow(8, cnt++);
			int a = s[i] - '0';
			long double m = a / z;
			//cout << m << endl;
			sum += m;
		}
		printf("%s [8] = %.50g [10]\n", s, sum);
	}
}

Double click to view unformatted code.


Back to problem 258