值​与C语言的总和不同
#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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在添加
a
和b
在用户输入任何值之前。扭转这两个。You are adding
A
andB
before the user has input any values. Reverse those two.C不是Excel。这样:
不要将
soma
的值与a+b
的值联系起来。这将soma
设置为当前a+b
的值,它们都没有初始化。您需要读取
a
和b
首先,然后基于此设置soma
的值。C is not Excel. This:
Does not tie the value of
SOMA
to the value ofA+B
. This setsSOMA
to the current value ofA+B
, neither of which has been initialized.You need to read the values of
A
andB
first, then set the value ofSOMA
based on that.C是一种急需的语言。
soma = a+b
是在您编写的地方执行的,即您甚至保存在a
和b
中输入的用户输入的值。(这是真的基本。也许找到更好的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 inA
andB
.(This is really basic. Maybe find a better introduction to C!)