簡體   English   中英

C ++ scanf / printf的數組

[英]C++ scanf/printf of array

我寫了以下代碼:

int main() {
    double A[2];
    printf("Enter coordinates of the point (x,y):\n");
    scanf("%d,%d", &A[0], &A[1]);

    printf("Coordinates of the point: %d, %d", A[0], A[1]);
    return 0;
}

它的行為如下:

輸入點(x,y)的坐標:

3,5

該點的坐標:3,2673912

怎么可能,5轉換成2673912?

您正在使用十進制整數格式(%d)讀取雙精度值。 嘗試使用雙格式(%lf)代替......

scanf("%lf,%lf", &A[0], &A[1])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM