zoukankan      html  css  js  c++  java
  • UVa 474

    题目:计算1/(2^n)的值的前4为有效数字以及位数。

    分析:数论,大整数。直接用数组模拟就可以。

    说明:打表计算。查询输出。

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath> 
    
    using namespace std;
    
    double val[1000005];
    int    bit[1000005];
    
    int main()
    {
    	val[0] = 1;bit[0] = 0;
    	for (int i = 1 ; i < 1000001 ; ++ i) {
    		val[i] = val[i-1]/2;
    		bit[i] = bit[i-1];
    		if (val[i] < 1) {
    			val[i] *= 10;
    			bit[i] --;
    		}
    	}
    	
    	int n;
    	while (~scanf("%d",&n))
    		printf("2^-%d = %.3lfe%d
    ",n,val[n],bit[n]);
    		
    	return 0;
    }
    

  • 相关阅读:
    NOIP提高组2004 合并果子题解
    RMQ问题之ST算法
    7.18考试
    7.18
    7.17
    7.16
    7.15
    7.14
    7.13考试
    7.13
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5116161.html
Copyright © 2011-2022 走看看