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
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
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
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
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
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…