Sum of two numbers without using arithmetic operators
Ex:int a=10;int b=10;int sum=a+b;without using "+" operator calculate sum
Answered by: jintojos
View all answers by jintojos
Member Since May-2008 | Answered On : Jul 17th, 2008
void main() { int a=10,b=20; while(b--) a++; printf("Sum is :%d",a); }
For two positive numbers: int main(){ int a = 10; int b = 10; printf("%d",a ^ b | ((a & b)<< 1)); return 0; }
Code#include<stdio.h> #include<conio.h> main() { int a=20,b=10,c; clrscr(); c=a-~b-1; //it will change the sign of operator truly magic printf("sum is %d",c); getch(); return 0; }
Engineering
Interview Coaching
Interview Questions
Tech FAQs
What are the things you wish to achieve in 5 years?
Do you find yourself busy most of the time? Why?
What do you think about continuous learning?
What is the role of a mechanical engineer in the Software Industry?
Do you like working in a team or alone? Explain.
How do you handle pressure and stress?
What are the career options available in Software Testing Industry?
How do you handle conflict?
How do you deal and overcome major challenges?
Has there been a time when you were presented a problem and solved it?
Ask Interview Question?
Have Career Question?
Ask Chandra
Ask Only Career questions.
Editorial / Best Answer
Answered by: jintojos
View all answers by jintojos
Member Since May-2008 | Answered On : Jul 17th, 2008
void main()
{
int a=10,b=20;
while(b--) a++;
printf("Sum is :%d",a);
}
For two positive numbers:
int main(){
int a = 10;
int b = 10;
printf("%d",a ^ b | ((a & b)<< 1));
return 0;
}