//Write a program to add, subtract, multiply and divide using if and operator(+, -, *, /)
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
char c;
cout<<”Enter a number:”;
cin>>a;
cout<<”Enter 2nd number:”;
cin>>b;
cout<<”Enter your choice+,-,*,/,%: “;
cin>>c;
cout<<endl;
if(c==’+’)
cout<<a+b;
else if(c==’-‘)
cout<<a-b;
else if(c==’*’)
cout<<a*b;
else if (c==’/’)
cout<<a/b;
else if(c==’%’)
cout<<a%b;
else
cout<<”Invalid Input”;
getch();
}
Output:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
char c;
cout<<”Enter a number:”;
cin>>a;
cout<<”Enter 2nd number:”;
cin>>b;
cout<<”Enter your choice+,-,*,/,%: “;
cin>>c;
cout<<endl;
if(c==’+’)
cout<<a+b;
else if(c==’-‘)
cout<<a-b;
else if(c==’*’)
cout<<a*b;
else if (c==’/’)
cout<<a/b;
else if(c==’%’)
cout<<a%b;
else
cout<<”Invalid Input”;
getch();
}
Output:
No comments:
Post a Comment