输入:1+2= 当输入等于号的时候表示输入结束,输出答案(只包含加减运算即可)
#include<stdio.h>
int main()
{
char operator0=0;
int operand1=0, res=0;
printf("输入加法计算:");
for(; ; )
{
scanf("%d", &operand1);
res=operand1;
while(operator0!='=')
{
scanf("%c",&operator0);
if(operator0=='=')break;
scanf("%d",&operand1);
if(operator0=='+')
{
res=res+operand1;
}
}
printf("%d\n", res);
break;
}
}
#include <stdio.h>
int main()
{
char ch,equl;
int a,b;
scanf("%d%c%d%c",&a,&ch,&b,&equl);
if(equl=='='&&(ch=='+'||ch=='-'))
{
if(ch=='+')
printf("%d\n",a+b);
if(ch=='-')
printf("%d\n",a-b);
}
else
{
printf("error\n");
}
return 0;
}
#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<a<<"+"<<b<<"="<<a+b;
return 0;
}
不知道你这个问题是否已经解决, 如果还没有解决的话: