C++ Online Compiler
Example: C++ Program to Perform Arithmetic Operations using Functions
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Perform Arithmetic Operations using Functions #include <bits/stdc++.h> using namespace std; // These functions will perform the all arithmetic operations void Sum(int p, int q) { int sum = p + q; cout << "SUM " << p << " + " << q << " = " << sum << "\n"; } void Difference(int p, int q) { int sub = p - q; cout << "DIFFERENCE " << p << " - " << q << " = " << sub << "\n"; } void Multiplication(int p, int q) { int mul = p * q; cout << "PRODUCT " << p << " * " << q << " = " << mul << "\n"; } void Division(int p, int q) { float div = (float)p / q; cout << "QUOTIENT " << p << " / " << q << " = " << div << "\n"; } void Modulus(int p, int q) { int mod = p % q; cout << "MODULUS " << p << " % " << q << " = " << mod << "\n"; } // It's the driver function int main() { int p, q; cout << "Enter any two numbers:\n"; cin >> p >> q; // It will perform the all arithmetic operations cout << endl; Sum(p, q); Difference(p, q); Multiplication(p, q); Division(p, q); Modulus(p, q); return 0; }
12 15
Output
Clear
ADVERTISEMENTS