Metoda cu if-else:
#include <iostream>
using namespace std;
int main()
{
int a,b;
char c;
cin>>a>>b>>c;
if(c=='+')
cout<<a+b<<endl;
else if(c=='-')
cout<<a-b<<endl;
else if(c=='*')
cout<<a*b<<endl;
else if(c=='/')
if(b!=0)
cout<<a/b<<endl;
else
cout<<"imposibil"<<endl;
else
cout<<"Introduceti un operator aritmetic valid!"<<endl;
return 0;
}
Metoda switch-case:
#include <iostream>
using namespace std;
int main()
{
int a,b;
char c;
cin>>a>>b>>c;
switch(c)
{
case '+':cout<<a+b<<endl;break;
case '-':cout<<a-b<<endl;break;
case '*':cout<<a*b<<endl;break;
case '/':if(b!=0)
cout<<a/b<<endl;
else
cout<<"Imposibil!"<<endl;
default:cout<<"Introduceti un operator aritmetic valid!"<<endl;
}
return 0;
}