标题:C 和指针编程练习 4.1
取消只看楼主
xiehou314159
Rank: 2
等 级:论坛游民
帖 子:35
专家分:86
注 册:2011-5-11
 问题点数:0 回复次数:0 
C 和指针编程练习 4.1
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
    float new_guess;
    float last_guess;
    float number;

    printf("Enter a number: ");
    scanf("%f", &number);

    if (number < 0) {
        printf("Cannot compute the square root of a negative number !\n");
        return EXIT_FAILURE;
    }

    new_guess = 1;
    do {
        last_guess = new_guess;
        new_guess = (last_guess+number/last_guess) / 2;
        printf("%.15e\n", new_guess);
    } while (new_guess != last_guess);  //这个地方为什么能直接用!=比较两个浮点变量?

    printf("Square root of %g is %g\n", number, new_guess);

    return EXIT_SUCCESS;
}
搜索更多相关主题的帖子: include number return Enter 
2014-06-18 17:30



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




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

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