| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1021 人关注过本帖
标题:What are diffenrences between "do while" and "while" ? ...
取消只看楼主 加入收藏
troyzyc
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2016-7-4
结帖率:56.6%
收藏
已结贴  问题点数:10 回复次数:1 
What are diffenrences between "do while" and "while" ?
#include <stdio.h>
#include <math.h>
int main()
 {
  float a,x0,x1;
  printf("enter a positive number:");
  scanf("%f",&a);
  
  x0=a/2;
  x1=(x0+a/x0)/2;
  do
   {x0=x1;
    x1=(x0+a/x0)/2;
   }while(fabs(x0-x1)>=1e-5);
  printf("The square root of %5.2f  is %8.5f\n",a,x1);
  return 0;
 }
这个程序是用do while编写,我想改成while循环,为什么下边的不对呢?求教大神?

#include<stdio.h>
#include<math.h>
int main()
{double a,x1,x0;
printf("please enter a:");
scanf("%d",&a);

x0=a/2;
x1=(x0+a/x0)/2;
while(fabs(x1-x0)<1e-5)
{
x1=0.5*(x0+a/x0);
x0=x1;
}
printf("%8.5f",x1);
return 0;
}
搜索更多相关主题的帖子: positive include between please double 
2016-11-17 20:35
troyzyc
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2016-7-4
收藏
得分:0 
回复 2楼 书生牛犊
那要改成while循环,怎么改呢?
2016-11-17 21:06
快速回复:What are diffenrences between "do while" and "while" ? ...
数据加载中...
 
   



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

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