C++ program for addition, subtraction, multiplication and division has been shown here. These are the basic arithmetic operations.
1. C++ Program & output to Perform Addition, Subtraction, Multiplication & Division
Code has been copied
/***************************************************************** alphabetacoder.com C++ program for addition, subtraction, multiplication and division *****************************************************************/ #include<iostream> using namespace std; int main(){ // declare variables double a, b, w, x, y, z; // take input cout<<"Enter first number: "; cin >> a; cout<<"Enter second number: "; cin >> b; // compute operations w = a + b; x = a - b; y = a * b; z = a / b; // display result cout<<"Addition: "<<w<<endl; cout<<"Subtraction: "<<x<<endl; cout<<"Multiplication: "<<y<<endl; cout<<"Division: "<<z<<endl; return 0; }
Output
Enter first number: 15
Enter second number: 2.5
Addition: 17.5
Subtraction: 12.5
Multiplication: 37.5
Division: 6
2. C++ Program & output to Perform Addition, Subtraction, Multiplication & Division using pointers
Code has been copied
/***************************************************************************** alphabetacoder.com C++ program for addition, subtraction, multiplication and division using pointers *******************************************************************************/ #include<iostream> using namespace std; int main(){ // declare variables double a, b, w, x, y, z, *n1, *n2; // take input cout<<"Enter first number: "; cin >> a; cout<<"Enter second number: "; cin >> b; //store the address in pointer n1 = &a; n2 = &b; // compute operations w = *n1 + *n2; x = *n1 - *n2; y = *n1 * *n2; z = *n1 / *n2; // display result cout<<"Addition: "<<w<<endl; cout<<"Subtraction: "<<x<<endl; cout<<"Multiplication: "<<y<<endl; cout<<"Division: "<<z<<endl; return 0; }
Output
Enter first number: 15
Enter second number: 2.5
Addition: 17.5
Subtraction: 12.5
Multiplication: 37.5
Division: 6