Tuesday 16 September 2014

write a c++ program to simulate a simple calculator to perform addition,substraction,multiplication and devision only on integer.

#include<iostream>
using namespace std;
int main()
{
char ch;
int a,b,result;
cout<<"enter two value "<<endl;
cin>>a>>b;
cout<<"enter the operator";
cin>>ch;

switch(ch)
{

      case '+':
              result=a+b;
              cout<<result;
              break;
      case '-':
            result=a-b;
            cout<<result;
            break;
      case '*':
              result=a*b;
            cout<<result;
            break;
      case '/':
            result=a/b;
            cout<<result;
            break;
      default:
        cout<<"enter correct operator";
        break;
}
}

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...