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

Suppose we have a table name EMP as below. We want to perform a operation in which, I want to change name ‘SMITH’ from as ‘SMITH JAIN’. Also I want to change the name of the column from ENAME to E_NAME. EMPNO ENAME JOB MGR HIREDATE SAL 7369 SMITH Coder 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250

0 Answers  


Explain how can you avoid including a header more than once?

0 Answers  


What are the primitive data types in c?

0 Answers  


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

0 Answers   HCL,


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

0 Answers  


What is the use of function overloading in C?

0 Answers   Ittiam Systems,


What is Bitwise Operator and how it works?

1 Answers  


What is the difference between fread and fwrite function?

0 Answers  


What is the benefit of using const for declaring constants?

0 Answers  


what is the difference between. system call and library function?

2 Answers   CDAC, Satyam,


can any one tel me wt is the question pattern for NIC exam

0 Answers   NIC,


What ios diff. Between %e & %f?

3 Answers   Honeywell,


Categories