Calculations

C++ Example to subtract two integer without using minus operator

C++ Example to subtract two integer without using minus operator

In this article, we will discuss the concept of the C++ Example to subtract two integer without using minus operator

In this post, we are going to learn how to  write a program to find the subtraction of two numbers using with out using minus operator in C++ programming language

subtract two integer without minus

Code to find the subtraction of  two numbers 

Subtract two integer without using minus

The program use to calculate subtraction of given two integer numbers without using minus operator in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int num1=200,num2=65,sub;
    //Variable declaration
    sub=num1+~num2+1;
    //find subtraction without minus
    cout<<"Subtraction of "<<num1<< " and "<<num2<<" is: "<<sub;
    //display the output
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Subtraction of 200 and 65 is: 135

 

Subtract two integer without using minus – Takes input from user

The program allow the user to enter two numbers and then calculates subtraction of given two integer numbers without using minus operator in C++ language

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int num1,num2,sub;
    cout<<"Enter the value for num1"<<endl;
    //ask input from user for num1
    cin>>num1;
    //string the value in num1
    cout<<"Enter the value for num2"<<endl;
    //ask input from user for num2
    cin>>num2;
    //string the value in num2
    sub=num1+~num2+1;
    //find subtraction without minus
    cout<<"Subtraction of "<<num1<< " and "<<num2<<" is: "<<sub;
    //display the output
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter the value for num1
500
Enter the value for num2
150
Subtraction of 500 and 150 is: 350

Methods

  1. Create two variables to store two numbers as input provided by the user: num1,num2;
  2. Create a variable to store the subtraction of these numbers: sub
  3. Request the user to enter first input for store variable num1
  4. Using cin>> store the first input value in num1
  5. Request the user to enter second input for store variable num2
  6. Using cin>> store the second input value in num2
  7. find the subtraction of num1,num2 without using minus operator
  8. Finally, display result on the screen- the subtraction of both numbers num1 and num2

 

Suggested for you

Operator in C++ language

Data type in C++ language

Variable in C++ language

if statements in C++ language

 

Similar post

Subtract two numbers in  C++  language

Subtract two numbers using function in C++ language

Subtract two numbers using recursion in C++ language

Find sum of two numbers in C++

Find sum of two numbers in C++ using recursion

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

C Example to subtract two integer without using minus operator
Example to subtract two integer using pointer in C
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…

1 month ago

PHP Full Pyramid pattern program

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

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

2 months ago

Python Full Pyramid star pattern program

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

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

10 months 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,…

10 months ago