addition

Cpp program to Addition Subtraction,Multiplication and division

Cpp program to Addition Subtraction, Multiplication and division

In this tutorial, we will discuss Cpp program to Addition Subtraction, Multiplication and division

 

Cpp program Aritmetic operators

In this post, we will learn how to perform addition, subtraction multiplication, division of any two numbers  using if else statements in Cpp programming

The  program will request the user to enter two number digits and the user select an operator to perform the addition, subtraction, multiplication, and division of the entered number by the user and displays the output on the screen
the program will display the result according to the user selection

Program 1

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int num1,num2;
    cout << "Enter two numbers" << endl;
    cin>>num1>>num2;
    cout<<"\nAddition of"<<num1<<"+"<<num2<<" = "<<num1+num2;
    cout<<"\nSubtraction of"<<num1<<"-"<<num2<<" = "<<num1-num2;
    cout<<"\nMultiplication of"<<num1<<"*"<<num2<<" = "<<num1*num2;
    cout<<"\nDivision of"<<num1<<"/"<<num2<<" = "<<num1/num2;
    getch();
    return 0;
}

When the above code is executed, it produces the following results

Enter two numbers
100
20

Addition of 100+20 = 120
Subtraction of 100-20 = 80
Multiplication of 100*20 = 2000
Division of 100/20 = 5

 

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    char ch;
    int num1,num2;
cout<<"Enter the first number: ";
cin>>num1;
cout<<"Enter the second number: ";
cin>>num2;
cout<<"Enter the operator you want(+, -, x, /) :";
cin>>ch;
if(ch=='+'){
    cout<<"Addition is :" <<num1+num2;
}
else if(ch=='-'){
    cout<<"Subtraction is :"<<num1-num2;
}

else if(ch=='+'){
    cout<<"Multiplication is :"<<num1*num2;
}

else if(ch=='+'){
    cout<<"Division is :"<<num1/num2;
}

else{
    cout<<"This operator not in use";
}

getch();
return 0;
}

When the above code is executed, it produces the following results

Case 1

Enter the first number: 60
Enter the second number: 10
Enter the operator you want(+, -, x, /):+
Addition is: 70

 

Case 2

Enter the first number: 60
Enter the second number: 10
Enter the operator you want(+, -, x, /):-
Subtraction is: 50

 

Case 3

Enter the first number: 100
Enter the second number: 10
Enter the operator you want(+, -, x, /):*
Multiplication is: 1000

 

Case 4

Enter the first number: 60
Enter the second number: 10
Enter the operator you want(+, -, x, /):/
Division is: 6

Case 5

Enter the first number: 60
Enter the second number: 10
Enter the operator you want(+, -, x, /):x
This operator not in use

 

Related program in other languages

Java Add Subtract Multiply Divide

C Add Subtract Multiply Divide

Python Add Subtract Multiply Divide

 

Suggested for you

The operator in the C++ language

If statements in C++ language

Data type in C++ language

 

 

Java code to multiplication table using Array
C Program to Addition Subtraction,Multiplication and division
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago