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
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…