C++ program to perform arithmetic operations by accepting inputs from a user
kw.cpp
#include <iostream>
using namespace std;
int main()
{
    float a, b;
    cout<<"———————————————————————————————————————————";
    cout<<"\nProgram to perform the arithmetic operations";
    cout<<"\n———————————————————————————————————————————";
    cout<<"\nEnter the 1st number ";
    cin>>a;
    cout<<"\nEnter the 2nd number ";
    cin>>b;
    cout<<"——————————————————————————";
    cout<<"\nAddition       | "<<a<<"+"<<b<<"="<<a + b;
    cout<<"\nSubtraction    | "<<a<<"-"<<b<<"="<<a - b;
    cout<<"\nMultiplication | "<<a<<"*"<<b<<"="<<a * b;
    cout<<"\nDivision       | "<<a<<"/"<<b<<"="<<a / b;
    cout<<"\n——————————————————————————";
    cout<<"\nAverage of 2 numbers is "<<(a + b) / 2;
    cout<<"\n———————————————————————————————————————————\n";
    return 0;
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to perform the arithmetic operations ——————————————————————————————————————————— Enter the 1st number 1 Enter the 2nd number 0 —————————————————————————— Addition | 1+0=1 Subtraction | 1-0=1 Multiplication | 1*0=0 Division | 1/0=inf —————————————————————————— Average of 2 numbers is 0.5 ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement