#include <stdio.h>
int main()
{
double i,sum1=0,sum2=0;
int sign=1,count;
scanf("%d",&count);
for(i=1.0;i<=count;i++,sign*=-1)
{
sum1+=1.0/i;
sum2+=sign*1.0/i;
}
printf("%.2f\n",sum1);
printf("%.2f\n",sum2);
return 0;
}
#include <stdio.h>
int main()
{
double i,sum1=0,sum2=0;
int sign=1,count;
scanf("%d",&count);
for(i=1.0;i<=count;i++,sign*=-1)
{
sum1+=1.0/i;
sum2+=sign*1.0/i;
}
printf("%.2f\n",sum1);
printf("%.2f\n",sum2);
return 0;
}
本文标题:练习2-6-6:序列收敛(循环结构)
本文链接:https://www.haomeiwen.com/subject/sgkyirtx.html
网友评论