C语言基础,写一个简单计算机的代码

输入:1+2= 当输入等于号的时候表示输入结束,输出答案(只包含加减运算即可)

img

#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;
}

}

img

#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;
}

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^