求大神指导,putchar和scanf的问题
#include<stdio.h>#include<stdlib.h>
int jia(int a,int b)
{
return a+b;
}
int jian(int a,int b)
{
return a-b;
}
int cheng(int a,int b)
{
return a*b;
}
int chu(int a,int b)
{
return a/b;
}
int mod(int a,int b)
{
return a%b;
}
void main()
{
char ch=getchar();
int a,b;
scanf("%d%d",&a,&b);
char ch=getchar();
if(ch=='+')
{
printf("\na+b=%d",jia(a,b));
}
if(ch=='-')
{
printf("\na-b=%d",jian(a,b));
}
if(ch=='*')
{
printf("\na*b=%d",cheng(a,b));
}
if(ch=='/')
{
printf("\na/b=%d",chu(a,b));
}
if(ch=='%')
{
printf("\na%%b=%d",mod(a,b));
}
system("pause");
}
标红的语句位置编译出来结果是对的,标绿的位置是错的,为什么位置变化导致结果不同,求指导!