标题:求助while(getchar()!='q')
取消只看楼主
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
 问题点数:0 回复次数:0 
求助while(getchar()!='q')
//13. 编写函数,求任意阶多项式 a0+a1X+a2X2+...+anXn 的值并返回多项式的值。
#include<stdio.h>
#include<math.h>
void main()
{
double a,x,sum=0;
int i=0;
printf("input the value of 'x':\n");
scanf("%lf",&x);
while(getchar()!='q')
{
printf("input a%d:\n",i);
scanf("%lf",&a);
sum+=a*pow(x,i);
i++;
}
printf("the last value is :%lf",sum);
}
我输入的是x=1,a1=1,a2=2,a3=1;然后输入的是q调处,答案输出应该是4,但是输出的是5
调试的时候发现是因为我输入q的时候while还是循环了一次,请问大家是while本身是这样还是我写的程序不对?
搜索更多相关主题的帖子: getchar 
2007-02-22 00:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-121384-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.890952 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved