C++ Program to find Sum, Multiplication, Division, Subtraction by Using Function

Write a c++ program to find sum, multiplication, division, subtraction by using function. Write a object oriented program to find the sum of the entered numbers. Write a c++ program to find the sum, mul, div, sub by using switch case. C++ program to find the sum, mul, div, sub by using function.

Write a c++ program to find sum, multiplication, division, subtraction by using function.
Write a object oriented program to find the sum of the entered numbers.
Write a c++ program to find the sum, mul, div, sub by using switch case.
C++ program to find the sum, mul, div, sub by using function.

C Code


#include<iostream.h>
#include<conio.h>
void add(int a,char c, int b);
  void sub(int a,char c, int b);
  void mul(int a,char c, int b);
  void div(int a,char c, int b);

void main(){
  int a,b;
  char c;
  cout<<"Enter 1st number:";
  cin>>a;
  cout<<"\nEnter operater:";
  cin>>c;
  cout<<"\nEnter 2nd number:";
  cin>>b;
  switch(c){
    case '+':  {
      add(a,c,b);
      break;
    }
    case '-' : {
      sub(a,c,b);
      break;
    }
    case '*' : {
      mul(a,c,b);
      break;
    }
    case '/' : {
          div(a,c,b);
          break;
    }
    default:
    break;
  }
  
  getch();
}

void add(int a,char c, int b){
  int s=a+b;
  cout<<"\nSum="<<s;
}
void sub(int a,char c, int b){
  int d=a-b;
  cout<<"\nDifference="<<d;
}
void mul(int a,char c, int b){
  int p=a*b;
  cout<<"\nProduct="<<p;
}
void div(int a,char c, int b){
  float q=float(a)/float(b);
  cout<<"\nQuotient="<<q;
}

You May Also Like...

Socialize with Us