how to add two numbers without using arithmetic operators?

Answers were Sorted based on User's Feedback



how to add two numbers without using arithmetic operators?..

Answer / sanjay bhosale

int x=12382,y=2;
int xor, and, temp;
and = x & y;
xor = x ^ y;

while(and != 0 )
{
and <<= 1;
temp = xor ^ and;
and &= xor;
xor = temp;
}
printf(" sum is : %d",xor);

Is This Answer Correct ?    0 Yes 0 No

how to add two numbers without using arithmetic operators?..

Answer / shashishekar

#include<stdio.h>
#include<conio.h>
int main()
{
int a= 10;
int b=5;
int sum=0;
sum= a-(~b)-1;
printf(" sum= %d",sum);
getch();
}

Is This Answer Correct ?    0 Yes 0 No

how to add two numbers without using arithmetic operators?..

Answer / mallikarjun

#include<stdio.h>
#include<conio.h>
main()
{
int a= 10;
int b=5;
sum=0;
sum= a&&b;
printf(" sum= %d",sum);
}

Is This Answer Correct ?    9 Yes 10 No

how to add two numbers without using arithmetic operators?..

Answer / rajkumar

#include<stdio.h>
#include<conio.h>
void main()
{
int a=6,b=3,sum=0;
sum=a^b;
printf("sum=%d",sum);
getch();
}

Is This Answer Correct ?    3 Yes 9 No

Post New Answer

More C Interview Questions

What are the advantages of using macro in c language?

0 Answers  


Is c easy to learn?

0 Answers  


How many types of errors are there in c language? Explain

0 Answers  


character array A[12] can hold

5 Answers   Wipro,


What is hashing in c?

0 Answers  






Can we add pointers together?

0 Answers  


Explain how are portions of a program disabled in demo versions?

0 Answers  


Difference between constant pointer and pointer to a constant.

0 Answers   Huawei,


Can you please compare array with pointer?

0 Answers  


How to calculate Total working time using Login and logout?

2 Answers   CTS, Cygnus, Infosys, Signal Networks, TCS, Wipro,


Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.

0 Answers  


Explain the advantages of using macro in c language?

0 Answers  


Categories