Thursday, 17 October 2013

CPP Program to Add, Subtract, Multiply and divide Using If and operators(+, -, *, /)

//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:

No comments:

Comments System