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

PHP Star Triangle pattern program

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

6 months ago

PHP Full Pyramid pattern program

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

6 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…

6 months ago

Python Full Pyramid star pattern program

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

9 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…

1 year 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,…

1 year ago