+1 vote
83 views
Is it possible to add two numbers without plus operator?
asked Oct 19, 2015 | 83 views
which programing language ? you can very well use predefined methods like sum() etc
Programming language like c or java. Give an example as how to use sum()? and in which language it is used?

+1 vote

In C programming ,you can use a tricky method as below :

#include <stdio.h>

{
return printf("%*c%*c",x,' ', y,' ');
}

int main()
{
return 0;
}

The above answer will print 4 spaces followed by 5 spaces,so total we have 9 characters(i.e 9 spaces),

When we use %d for 9 characters we have result as 9.

But why go round the head when you can print in single line as sum=x+y ; :)

In predefined method case like in c#.net you can use as below :

  int [] z={1,2};
MessageBox.Show("" + z.Sum().ToString()); //prints output i message box

Good for c program, actually for java program is there any other method?
@T.PRATHIBA  You have already stated : "Programming language like c or java. Give an example as how to use sum()? and in which language it is used?" ..so this answer must be the solution you can accept know
ok ok, but there is another method, c=a+b can be written as c=a-(-b); that's it without + symbol we have added two numbers and we can use this in any language.
Ha ha..yes you are correct..but why would some one use - - if you can take directly + ,because every character has affect on code metrics know..but its a good puzzle :)..you can add your answer also at enggforum.com so that other students get the correct answer and no question should be without answers...