C语言中遇到的问题:程序原意是如果输入的是y则跳出while循环,否则一直循环。但运行后结果不理想。求原因

[复制链接]
查看11 | 回复3 | 2012-4-7 23:28:27 | 显示全部楼层 |阅读模式
你问题都问错了,应该是输入的是y则一直循环,给你改好程序了#include void main() { char ch; do { float r; printf("请输入圆的半径r="); scanf("%f",&r); printf("圆的周长为:%f\n",2*3.1415*r); printf("是否继续? y/是n/否"); fflush(stdin); ch=getchar(); printf("ch=%c\n",ch); }while(ch=='y'); printf("%c\n",ch); }...
回复

使用道具 举报

千问 | 2012-4-7 23:28:27 | 显示全部楼层
这样改应该对了#include void main() {// char ch='y'; 这一句就不要了,OK了 while(ch=='y') { float r; printf("请输入圆的半径r="); scanf("%f",&r); printf("圆的周长为:%f\n",2*3.1415...
回复

使用道具 举报

千问 | 2012-4-7 23:28:27 | 显示全部楼层
#include void main() { char ch='y'; while(ch=='y') { float r; printf("请输入圆的半径r="); scanf("%f",&r); printf("圆的周长为:%f\n",2*3.1415*r); printf("是否继续? y/...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行