码迷,mamicode.com
首页 > 编程语言 > 详细

【c语言】求1-1/2+1/3-1/4...+1/99-1/100

时间:2015-04-23 13:22:55      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

// 求1-1/2+1/3-1/4...+1/99-1/100

#include <stdio.h>

int main()
{
	double a = 1.0;
	int i;
	double sum = 1.0;
	for( i = 2; i <= 100; i++ )
	{
		a = (-1) * a;
		sum = sum + a/i;	
	}
	printf("1-1/2+1/3-1/4...+1/99-1/100=%f\n",sum);
	return 0;
}

<img src="http://img.blog.csdn.net/20150423114517322?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

【c语言】求1-1/2+1/3-1/4...+1/99-1/100

标签:

原文地址:http://blog.csdn.net/zhaoyaqian552/article/details/45219715

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!