C++数组的 scanf/printf

发布于 2024-09-27 03:23:47 字数 369 浏览 0 评论 0原文

我写了以下代码:

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?

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, 2673912

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城凉梦凉人心 2024-10-04 03:23:47

您正在使用十进制整数格式 (%d) 读取双精度值。
尝试使用双精度格式 (%lf) 代替...

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

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])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文