0 votes
108 views
in Programming by (98.9k points)
edited
To write C++ Program using operators

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
// Program to perform given operation on two input integers 
#include<iostream.h> {

void main()

{

int a, b, c, d, e;

char oper;

float f;

cout<<"Enter the first number:";

cin>>a;

cout<<"Enter the operator:";

cin>>oper;

cout<<"Enter the second number:";

cin>>b;

if (oper=='+')

{

c = a +b;

cout <<"the result is:"<<c;

else if(oper=='-')

{

d=a-b; cout<<"the result is:"<<d;

} else if (oper=='*') {

e = a*b; cout<<"the result is:"<<e;

} else if (oper=='/')

if (b==0)

{

} else



f=(float)a/b;

cout<<"the result is : "<<f;

}

}

else 

cout<<"invalid operator";

}

Related questions

0 votes
1 answer 1.5k views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

559 users

...