顯示文章

這裡允許您檢視這個會員的所有文章。請注意, 您只能看見您有權限閱讀的文章。


主題 - student f

頁: [1]
1
C/C++程式設計討論區 / 請教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");
    }
}

2
C/C++程式設計討論區 / 請教C語言問題
« 於: 2021-03-22 02:40 »
題目:輸入一個英文字母,輸出其大寫字母
我打的程式碼如下:

#include <stdio.h>
int main()
{
    while(1==1)
    {
        char ch;
        printf("input char = ");
        scanf("%c",&ch);

        if(ch<90)
        {
            printf("char is : %c\n\n",ch);
        }
        else
        {
            ch-=32;
            printf("char is : %c\n\n",ch);
        }
    }
}

請問輸出時,為何會多跑出下面這一行,沒用while時不會出現,但我想讓它可以重複輸入,不知道是哪裡出錯了,麻煩大家了。

input char = char is :


頁: [1]