开发者

C++ scanf/printf of array

开发者 https://www.devze.com 2023-01-19 07:26 出处:网络
I\'ve written following code: int main() { double A[2]; printf("Enter coordinates of the point (x,y):\\n");

I've written following code:

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;
}

It's acting like this:

Enter coordinates of the point (x,y):

3,5

Coordinates of the point: 3, 2开发者_StackOverflow673912

How is it possible, that 5 converts into 2673912??


You are reading double values using the decimal integer format (%d). Try using the double format (%lf) instead...

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

精彩评论

暂无评论...
验证码 换一张
取 消