Addition of two number using '-' operator Last Updated : 13 Mar, 2023 Comments Improve Suggest changes Like Article Like Report The task is to Add two number using '-' operator. Examples: Input : 2 3Output : 5 Input : 10 20Output : 30 The idea is simple, we subtract -b from a. C++ // CPP program to add two numbers using // - operator. #include <bits/stdc++.h> using namespace std; // function to add two numbers. int add(int a, int b) { return a - (-b); } // Driver code int main() { int a = 2, b = 3; cout << add(a, b) << endl; return 0; } Java // Java program to add // two numbers using // - operator. import java.io.*; class GFG { // function to add two numbers. static int add(int a, int b) { return a - (-b); } // Driver code public static void main (String[] args) { int a = 2, b = 3; System.out.print(add(a, b)); } } // This code is contributed // by chandan_jnu Python3 # Python 3 program to add two numbers # using - operator. # Function to add two numbers def add(a, b): return (a - (-b)) # Driver code if __name__ == "__main__" : a = 2 b = 3 print(add(a, b)) # this code is contributed by Naman_Garg C# // C# program to add // two numbers using // - operator. class GFG { // function to add two numbers. static int add(int a, int b) { return a - (-b); } // Driver code static void Main() { int a = 2, b = 3; System.Console.WriteLine(add(a, b)); } } // This code is contributed // by mits PHP <?php // PHP program to add two // numbers using - operator. // function to add two numbers. function add($a, $b) { return $a - (-$b); } // Driver code $a = 2; $b = 3; echo add($a, $b); // This code is contributed by mits ?> JavaScript <script> // Javascript program to add two numbers using // - operator. // Function to add two numbers. function add(a, b) { return a - (-b); } // Driver code var a = 2, b = 3; document.write(add(a, b)); // This code is contributed by itsok </script> Output: 5 Time complexity: O(1)Auxiliary Space: O(1), As constant extra space is used. Comment More infoAdvertise with us Next Article Addition of two number using '-' operator N Naman_Garg Follow Improve Article Tags : C++ Programs Computer Science Fundamentals DSA cpp-operator Practice Tags : cpp-operator Similar Reads Subtraction of two numbers using 2's Complement Given two numbers a and b. The task is to subtract b from a by using 2's Complement method.Note: Negative numbers represented as 2's Complement of Positive Numbers.For example, -5 can be represented in binary form as 2's Complement of 5. Look at the image below: Examples: Input : a = 2, b = 3 Output 12 min read Add Two Numbers in C++ Given two integers, the task is to add these integer number and print their sum in C++.ExamplesInput: a = 11, b = 9Output: 20Explanation: Sum of 11 + 9 = 20Input: a = 1, b = 8Output: 9Explanation: Sum of 1 + 8 = 9 Add Two Numbers Using Addition OperatorIn C++, the simplest method for adding the two 3 min read Count the number of carry operations required to add two numbers Given two numbers, the task is to find the number of carry operations required when two numbers are added as below. 1234 + 5678 -------- 6912 -------- Examples: Input: n = 1234, k = 5678 Output: 2 4+8 = 2 and carry 1 carry+3+7 = carry 1 carry+2+6 = 9, carry 0 carry+1+5 = 6 Input: n = 555, k = 555 Ou 8 min read Increment a number without using ++ or + The task is to Increment a number without using ++ and + operators.Examples: Input : 3 Output : 4 Input : 9 Output : 10 The idea is based on the fact that the negative numbers are stored using 2's complement form. 2's complement form is obtained by inverting bits and then adding one. So if we invert 6 min read C++ Program to Make a Simple Calculator A simple calculator is a device used to perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It makes arithmetic calculations easier and faster. In this article, we will learn how to code a simple calculator using C++.ExamplesInput: Enter an operator (+, - 3 min read Like