scanf的输入格式

各位大佬,我初学c语言,遇上了点问题。

#include<stdio.h>
int main()
{
int a,b,s;
scanf("s=%d+%d",&a,&b);
printf("%d\n",s);
return 0;
}

这个程序能运行,但不管输入什么数,这个输出结果一直是1

scanf中不要写多余的字符,直接scanf("%d%d",&a,&b);就行了

你要按照scanf中的格式写。
要写 s= 1+1

img

img

由于scanf不会对变量进行运算。
所以s还是0

scanf是读取键盘上输入的数,你这个s=%d+%d是个无效的式子


```c
#include<stdio.h>
int main()
{
int a,b,s;
scanf("%d,%d",&a,&b);
s=a+b;
printf("%d\n",s);
return 0;
}

```

scanf - scan format
printf - print format