作者 主題: 請教C語言問題  (閱讀 2651 次)

0 會員 與 1 訪客 正在閱讀本文。

student f

  • 可愛的小學生
  • *
  • 文章數: 4
    • 檢視個人資料
請教C語言問題
« 於: 2021-04-01 15:20 »
程式碼如下,我預設讓y不等於零的時候輸出,請問為什麼y等於零時也會輸出 ???

#include <stdio.h>
#include <math.h>
#include <time.h>

int main()
{
    while(1)
    {
        double a,b,c,x;
        double start,end,d;
        double y;

        printf("input a,b,c:");
        scanf("%lf %lf %lf",&a,&b,&c);


        printf("input start,end,d:");
        scanf("%lf %lf %lf",&start,&end,&d);

        end+=d;

        for(x=start; x<end; x+=d)//from x to end
        {
            y=a*x*x+b*x+c;

            if(y!=0)
            {
                printf("x=%lf\t",x);
                printf("y=%lf\n",y);
            }

        }
        printf("\n");
    }
}

twu2

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 5417
  • 性別: 男
    • 檢視個人資料
    • http://blog.teatime.com.tw/1
Re: 請教C語言問題
« 回覆 #1 於: 2021-04-02 14:50 »
因為只印出小數點後六位, 實際上後面還有.

student f

  • 可愛的小學生
  • *
  • 文章數: 4
    • 檢視個人資料
Re: 請教C語言問題
« 回覆 #2 於: 2021-04-04 01:59 »
太感謝了,
我朝小數點後這個方向去網路上找,
發現判斷浮點數不能用和整數行相同的方式,
之後也成功了,謝謝您的回覆  :) :)
« 上次編輯: 2021-04-04 02:00 由 student f »