#include<stdio.h>
void main
{
int x,y;
char op;
printf("inputx op y in order %d%c%d",x,op,y);
scanf("%d%c%d",x,op,y>;
switch(op)
{ case(+) printf("x+y=%d",x+y); break; case(-) printf("x-y=%d",x-y); break;
}
#include<stdio.h>
void main
{
int x,y;
char op;
printf("inputx op y in order ");
scanf("%d%c%d",&x,&op,&y);
switch(op)
{
case(+)
printf("x+y=%d",x+y); break;
case(-)
printf("x-y=%d",x-y); break;
}
由于手里没工具,你先试试对不对
程序存在的问题: 输入函数scanf()格式错误,switch语句格式错误,单个字符要用一对单引号‘’括起来…… 以后多细心点吧……
#include<stdio.h>
main()
{int x,y; char op; printf("input x op y in order %d%c%d"); scanf("%d%c%d",&x,&y,&op); switch(op) { case '+': printf("x+y=%d",x+y); break; case '-': printf("x-y=%d",x-y); break; }
}
这样就可以了
#include <stdio.h>
main()
{
int x,y;
char op;
printf("inputx op y in order ");
scanf("%d%c%d",&x,&op,&y);
switch(op)
{
case('+'):
printf("x+y=%d",x+y); break;
case('-'):
printf("x-y=%d\n",x-y);
}}
#include<stdio.h>
void main()
{
int x,y;
char op;
printf("inputx op y in order ",x,op,y);
scanf("%d%c%d",x,op,y);
switch(op)
{
case('+'):
printf("x+y=%d",x+y); break;
case('-'): printf("x-y=%d",x-y); break;
}
}
#include<stdio.h>
void main
{
int x,y;
char op;
printf("inputx op y in order %d%c%d",x,op,y);
scanf("%d%c%d",x,op,y>;
switch(op)
{
case(+)
printf("x+y=%d",x+y); break;
case(-)
printf("x-y=%d",x-y); break;
}
你的x,y,op还没有赋值,你就输出是不对的
改成
printf("inputx op y in order ");
scanf("%d%c%d",&x,&op,&y);