*/ *Copyright(c)2013,烟台大学计算机学院学生 *All rights reserved. *文件名称:见标题 *作者:张凯 *完成日期:2013年 10 月29 日 *版本号:v1.0 *求解的问题: */ #include <iostream> #include<cmath> using namespace std; int main() { double s=0,p=1; int i=0,t=1; while(i<=8) { s=s+t*p; t=-t; p=p*0.5; i++; } cout<<"s="<<s<<endl; return 0; }
运行结果 (如下图)
心得体会:不用pow更能扩展自己的思维