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
How to handle academic gap while applying for a job?
Aptitude Test Preparation Tips
How productive are you?
What was the most important decision you ever had to make?
What do you think about our company?
Careers and Higher Education Options for BBA Graduates
What are the things you wish to achieve in 5 years?
What are the career options available in Software Testing Industry?
What is your way of building rapport with a person you just met?
What is the role of a mechanical engineer in the Software Industry?
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;
}