输入后无结果显示
#include <stdio.h>int main(void)
{
double sums_1,sums_2;
int sign,times,n;
n=1;
printf("Please input the number of times you want\n");
scanf("%d",×);
for(sums_1=0.0,sums_2=0.0;n<=times;n++)
{
sums_1+=1.0/(double)n;
for(sign=1;sign<=n;sign++)
sign*=-1;
sums_2+=sign*1.0/(double)n;
}
printf("The result of %d times is %lf and %lf\n",times,sums_1,sums_2);
return 0;
}
编译环境VC++6.0
输入后无结果显示,编译没有报错
已经改正
#include <stdio.h>
int main(void)
{
double sums_1,sums_2;
int sign,times,n;
sign=1;
sums_1=0.0,sums_2=0.0;
printf("Please input the number of times you want\n");
scanf("%d",×);
for(n=1;n<=times;n++)
{
sums_1+=1.0/n;
sums_2+=sign*1.0/n;
sign*=-1;
}
printf("The result of %d times is %lf and %lf\n",times,sums_1,sums_2);
return 0;
}
原因符号没有控制好,思路不够清晰
[ 本帖最后由 小小熊宝宝 于 2010-9-10 13:02 编辑 ]