C语言编程:求s=1-1/2+1/4-1/6+1/8……1/1O
1个回答
展开全部
#include <stdio.h>//望采纳!!!
int main(void)
{
double s=1.0,n=2.0;
int a=2;
for (;n<=10.0;)
{
if (a%2==0)
{
s = s-1.0/n;
}
else
{
s = s+1.0/n;
}
n=n+2.0;
a++;
}
printf ("s=1-1/2+1/4-1/6+1/8……1/1O=%lf\n",s);
}
int main(void)
{
double s=1.0,n=2.0;
int a=2;
for (;n<=10.0;)
{
if (a%2==0)
{
s = s-1.0/n;
}
else
{
s = s+1.0/n;
}
n=n+2.0;
a++;
}
printf ("s=1-1/2+1/4-1/6+1/8……1/1O=%lf\n",s);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询