标题: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



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




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

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