Subtract two numbers in C++ programming
- Home
- Calculations
- Subtract two numbers in C++ programming
- On
- By
- 0 Comment
- Categories: Calculations
Subtract two numbers in C++ programming
Subtract two numbers in C++ programming
In this article, we will discuss the concept of the Subtract two numbers in C++ programming
In this post, we are going to learn how to write a program to find the subtraction of two numbers in C++ programming language
Subtract two integer numbers
The program use to find subtraction of given two integer numbers
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int num1=366,num2=189; //variable declaration int sub=num2-num1; //formula of subtraction cout<<"Differences of two numbers are: "<<sub; //display the result getch(); return 0; }
When the above code is executed, it produces the following result
Differences of two numbers are: -177
Subtract two integer numbers using user input
This program allows the user to enter two integer numbers Then the program find the subtraction of the given two number
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int num1,num2; //variable declaration cout<<"Enter two integer for subtract: "; cin>>num1>>num2;//read the inputs int sub=num2-num1; //formula of subtraction cout<<"Differences between two numbers are: "<<sub; //display the result getch(); return 0; }
When the above code isexecuted, it produces the following result
case 1
Enter two integer for subtract: 456 567 Differences between two numbers are:111
case 2
Enter two integer for subtract: 567 456 Differences between two numbers are:-111
Subtract two float numbers
The program use to find subtraction of given two float numbers
Program 3
#include <iostream> #include <conio.h> using namespace std; int main() { float num1=544.567,num2=767.324; //variable declaration and initialization float sub=num2-num1; //formula of subtraction cout<<"Differences between two numbers are: "<<sub; //display the result getch(); return 0; }
When the above code isexecuted, it produces the following result
Differences between two numbers are:222.757
Subtract two float numbers using user input
This program allows the user to enter two float numbers Then the program find the subtraction of the given two number
Program 4
#include <iostream> #include <conio.h> using namespace std; int main() { float num1,num2; //variable declaration and initialization cout<<"Enter two float numbers: "; cin>>num1>>num2;//read the inputs float sub=num2-num1; //formula of subtraction cout<<"Differences of two numbers are: "<<sub; //display the result getch(); return 0; }
When the above code isexecuted, it produces the following result
case 1
Enter two float numbers: 123.456 234.567 Differences between two numbers are:111.111
case 2
Enter two float numbers : 234.567 123.456 Differences between two numbers are:-111.111
Suggested for you
Similar post
Find sum of two numbers in C++
Find sum of two numbers in C++ using recursion
Find sum of two numbers in C++ using pointer
Find sum of two numbers in C++ without Arithmetic operator
Find sum of natural numbers in C++ language
Find sum of natural numbers in C++ language using recursion