值​与C语言的总和不同

发布于 2025-02-02 14:41:42 字数 333 浏览 3 评论 0原文

#include <stdio.h>

int main() {
    int A, B;
    int SOMA = A+B;
    scanf("%d%d", &A, &B);
    printf("SOMA = %d\n", SOMA);

    return 0;
}

/*
INPUT --> OUTPUT
30 10 --> SOMA = 16
1  3  --> SOMA = 16
300 1000 --> SOMA = 16
*/

为什么我要获得这些结果而不是总和? 我想要一条消息“ soma = sumvalue”。

#include <stdio.h>

int main() {
    int A, B;
    int SOMA = A+B;
    scanf("%d%d", &A, &B);
    printf("SOMA = %d\n", SOMA);

    return 0;
}

/*
INPUT --> OUTPUT
30 10 --> SOMA = 16
1  3  --> SOMA = 16
300 1000 --> SOMA = 16
*/

why am i getting these results instead of the sum?
I wanted the message "SOMA = sumValue" with the end of the line.

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

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

发布评论

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

评论(3

无风消散 2025-02-09 14:41:42
int SOMA = A+B;
scanf("%d%d", &A, &B);

您正在添加ab在用户输入任何值之前。扭转这两个。

int SOMA = A+B;
scanf("%d%d", &A, &B);

You are adding A and B before the user has input any values. Reverse those two.

丢了幸福的猪 2025-02-09 14:41:42

C不是Excel。这样:

int SOMA = A+B;

不要将soma的值与a+b的值联系起来。这将soma设置为当前 a+b的值,它们都没有初始化。

您需要读取ab首先,然后基于此设置soma的值。

scanf("%d%d", &A, &B);
int SOMA = A+B;

C is not Excel. This:

int SOMA = A+B;

Does not tie the value of SOMA to the value of A+B. This sets SOMA to the current value of A+B, neither of which has been initialized.

You need to read the values of A and B first, then set the value of SOMA based on that.

scanf("%d%d", &A, &B);
int SOMA = A+B;
前事休说 2025-02-09 14:41:42

C是一种急需的语言。 soma = a+b是在您编写的地方执行的,即您甚至保存在ab中输入的用户输入的值。

(这是真的基本。也许找到更好的C介绍!)

C is an imperative language. SOMA = A+B is executed where you wrote it, i.e. before you even saved the values the user entered in A and B.

(This is really basic. Maybe find a better introduction to C!)

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