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 numbers

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

Operator in C++ language

Data type in C++ language

Variable in C++ language

 

 

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

 

 

 

 

Write a program to Subtract two numbers in Java
C Program to find Subtraction of two numbers
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

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

1 day ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago