Click here to Skip to main content
15,885,716 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Is it possible to add numbers without using the '+' operator?
WITHOUT SUBTRACTION
Posted
Updated 7-Feb-14 19:06pm
v2
Comments
Maarten Kools 6-Feb-14 16:19pm    
Why would you want to?
Richard C Bishop 6-Feb-14 16:21pm    
I can't imagine that there could be unless some abstract method was concocted and I can't even begin to think how you would go about creating that.
BillWoodruff 7-Feb-14 0:58am    
Are you re-inventing the wheel ?
The Kcrownikown 8-Feb-14 1:05am    
Yep

Yes, of course
C#
int a = 5;
int b = 10;
int c = a - (-b);
 
Share this answer
 
Comments
Andrius Leonavicius 6-Feb-14 16:41pm    
*Brackets are optional. ;)
CPallini 6-Feb-14 16:52pm    
**They are sexy ;-)
Andrius Leonavicius 6-Feb-14 16:55pm    
I can agree on that. :)
The Kcrownikown 8-Feb-14 1:06am    
Can I do it without using subtraction
agent_kruger 8-Feb-14 3:19am    
this is correct but why so difficult wen we can use (+).
C#
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static void Main(string[] args)
    {
        int a = 34;
        int b = 55;
        int[] array = {a,b };
        int sum = array.Sum(); //89

    }

}
 
Share this answer
 
The "Bitwise operations in C" Wikipedia's page, provides an example[^].
 
Share this answer
 
Its possible with bitwise operations.
You can find some implementations if you search on the internet.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900