Can any one add two numbers without using + operator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can any one add two numbers without using + operator?

12th Nov 2016, 5:50 AM
gowtham
gowtham - avatar
8 Answers
+ 7
#include<stdio.h> int main() { int num1 = 16, num2 = 14, i; //Result should be 30 while (num2 > 0) { num1++; num2--; } printf("%d", num1); return (0); } In this example, I use the while loop to do it. " #include<stdio.h> " allows me to use "printf" which is the same as using 'cout' to print out text, but I prefer to use printf By the way, this is for C++, not really for Java
12th Nov 2016, 6:00 AM
Wen Qin
Wen Qin - avatar
+ 6
#include<stdio.h> //Insert main here int y = 4; int x = 6; //we are going to do y+x int z = -1; while (!(x==-6)) { x--; } x = x-y; int Result = x/z; printf("%d", Result); return (0); //outputs 10. No plus operator used, only minus
13th Nov 2016, 3:37 AM
Wen Qin
Wen Qin - avatar
+ 1
nope + is used still... I don't wanna see + operator at all
12th Nov 2016, 2:09 PM
gowtham
gowtham - avatar
+ 1
int no1,no2; while(no1--) no2++; cout<<no2; //use it only if no1 is +ve ☺
13th Nov 2016, 9:12 AM
Pankaj Devesh
Pankaj Devesh - avatar
0
Nope. if you use decrement(++),it also use + operator😂
12th Nov 2016, 3:24 PM
Dandi Wiratsangka
Dandi Wiratsangka - avatar
0
Yes! it's possible via Binary Operators and bitwise operators. Check below for code.
13th Nov 2016, 1:59 AM
Saif Ali
Saif Ali - avatar
0
// Half Adder logic - Recursive approach // Not my implementation int add(int a,int b) { int sum,carry; if (b == 0) return a; sum = a ^ b; // add without carrying carry = (a & b) << 1; // carry, but don’t add return add(sum,carry); // recurse }
13th Nov 2016, 2:02 AM
Saif Ali
Saif Ali - avatar
0
//let the two numbers are : int n1,n2; //then while(n1--) n2=-(-n2-1); //👉n2 is the required sum //without using +or++ operator court<<n2;
20th Nov 2016, 1:22 PM
Pankaj Devesh
Pankaj Devesh - avatar