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 / selloorhari

#include <stdio.h>
int add(int a, int b)
{
if (!a)
return b;
else
return add((a & b) << 1, a ^ b);
}

int main()
{
unsigned int a,b;
printf("Enter the two numbers: \n");

scanf("%d",&a);
scanf("%d",&b);
printf("Sum is: %d",add(a,b));
}

Is This Answer Correct ?    168 Yes 30 No

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

Answer / kiran

Please explain me the code

Is This Answer Correct ?    42 Yes 20 No

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

Answer / pakalapati vijaya rama raju

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c=1;
clrscr();
printf("enter the two numbers");
scanf("%d%d",&a,&b);
while(c<=b)
{
a++;
c++;
}
printf("%d",a);
getch();
}

Is This Answer Correct ?    16 Yes 4 No

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

Answer / selloorhari

Hi,
This is the code for a FULL ADDER circuit.

Is This Answer Correct ?    22 Yes 12 No

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

Answer / pradeep

prashant answer is wrong suppose add two similar numbers
prashant answers will fail because addtion of two similar
bits according to the bitwise xor fails.

Is This Answer Correct ?    17 Yes 10 No

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

Answer / selloorhari

Hi Nitish,

If we will do the LOGICAL OR function then we will get
either 1 or 0.
If we will do the BITWISE OR then we will get the largest of
the two..

For
ex:
Let us take, First number as 2 and Second number as 3..
Then as per the first case we will get 1 as the output.
10(2) || 11(3) -> 1(1)
As per the second case the output will be 3..
10(2) | 11(3) -> 11(3).
Ok

Is This Answer Correct ?    14 Yes 12 No

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

Answer / srinu

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,i,j,k=0;
printf("enter 2 numbers");
scanf("%d%d",&a,&b);
if(a>b)
{
k=b;
for(i=1;i<=a;i++)
k++;
}
else
{
k=a;
for(j=1;j<=b;j++)
k++;
}
printf("sum of 2 numbers is %d",k);
}

Is This Answer Correct ?    1 Yes 2 No

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

Answer / roopali

#include<stdio.h>
int sum(int num1, int num2);
int main()
{
int num1, num2, result;
printf("Enter the number:");
scanf("%d%d",&num1,num2);
result=sum(num1,num2);
printf("The sum of two numbers is:%d",result);
return 0;
}

int sum(int num1, int num2)
{
int i;
for(i=0;i<num2;i++)
{
num1++;
}
return num1;
}

Is This Answer Correct ?    3 Yes 5 No

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

Answer / jayanth kothapalli

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
Printf("Enter Two numbers:");
scanf("%d,%d",&a,&b);
c=-(-a-b);
printf("sum is = %d",c);
getch();
}

Is This Answer Correct ?    2 Yes 5 No

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

Answer / chirantan

//program to add two numbers without using + operator//
#include<stdio.h>
main()
{
int a,b,c;
printf("\n enter two numbers to add\n");
scanf("%d %d", &a,&b);
c=((a*a)-(b*b))/(a-b);
}

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More C Interview Questions

#include<stdio.h> main() { int i=5; printf("%d",i*i-- - --i*i*i++ + ++i); } tell the answer with correct reason .specially reason is important nt answer ans by turbo c is -39

1 Answers   GameLoft,


What is a example of a variable?

0 Answers  


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

0 Answers  


what is mallloc()?how it works?

4 Answers   Excel,


What is the hardest programming language?

0 Answers  


What is the difference between File pointer and Internal Charecter Pointer?

2 Answers   TATA,


Is c functional or procedural?

1 Answers  


program to find out date after adding 31 days to a date in the month of febraury also consider the leap year

0 Answers  


wap to print "hello world" without using the main function.

22 Answers   TCS, Wipro,


main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(“%d”,x); }

8 Answers   Vector,


Which is more efficient, a switch statement or an if else chain?

0 Answers  


write a program to swap bits in a character and return the value prototype of function char fun (char a, charb flag c) where fun returns a char, char a is a the value char b is the bit to be changed and flag c is the bit value for eg: x=fun(45,7,0) since 45 is 0010 0101 and ow x should contain the value 65 (0110 0101)

1 Answers   Bosch, College School Exams Tests,


Categories