ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
How to add two numbers without using arithmetic operators?
 Question Submitted By :: Gopi
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 1
#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 ?    23 Yes 7 No
Selloorhari
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 2
Please explain me the code
 
Is This Answer Correct ?    7 Yes 4 No
Kiran
 
 
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 3
Hi,
This is the code for a FULL ADDER circuit.
 
Is This Answer Correct ?    3 Yes 5 No
Selloorhari
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 4
why cant we just or the two numbers
 
Is This Answer Correct ?    2 Yes 7 No
Nitish
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 5
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 ?    2 Yes 3 No
Selloorhari
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 6
int sum(int num1,int num2)
{	
     for(int i=0;i<num2;i++)	
        num1++;	
     return num1;
}
 
Is This Answer Correct ?    8 Yes 12 No
Pugalarasu
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 7
even this gives the same ans as the above program gives...
just every one plz check it and tell me
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
printf("enter the nos");
scanf("%d %d",&b,&c);
a= (b^c);
printf("%d",a);
return 0;
}
 
Is This Answer Correct ?    0 Yes 20 No
Prashant
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 8
#include<stdio.h>
int a,b,c;
{
printf("enter the two values");
scanf("%d","%d",&a,&b);
c=a||b;
}
 
Is This Answer Correct ?    0 Yes 8 No
Kavi
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 9
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 ?    2 Yes 1 No
Pradeep
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 10
# include <stdio.h>
main()
{
int a=8,b=2;
a|=b;
printf("sum="+a);
}
 
Is This Answer Correct ?    0 Yes 1 No
Suhas
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 11
#include<stdio.h>
main()
{
int a=5,b=4,c;
c=a||b;
printf("sum="+c);
}
 
Is This Answer Correct ?    0 Yes 1 No
Ranjith
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf("hello \n"); return 0; } int fun() { printf("hi"); } answer is hello.how??wat is tat while(i) mean? Intel4
Can we include one C program into another C program if yes how? Infosys4
how to convert binary to decimal and decimal to binary in C lanaguage  4
difference between i++* and *++i IBM3
pgm in c to reverse string by word using array(god is love becomes love is god) (no additional array can used,space is only delimiter between words ) Persistent1
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output? Ramco7
pick out the odd one out of the following a.malloc() b.calloc() c.free() d.realloc() TCS1
why you will give me a job in TCS. TCS5
Why the use of alloca() is discouraged? Oracle2
how to find the kth smallest element in the given list of array elemnts. Silicon5
What are bit fields? What is their use? Adobe1
what is difference between c and c++  3
how can we use static and extern?and where can we use this? Excel3
If "AaBbCc" is passed to the char char x(*a) { a[0]?x(a+1):1; printf("%c",a[0]); return 1; } what will be the output? Hughes5
WRITE A C PROGRAM TO FIND SECOND BIGGEST VALUE FROM THE GIVEN VALUES  1
write a programe returns the number of times the character appears in the string  1
actually i have 2 years teaching experience as computer faculty but now i am a DBA but when i go for interview many peoples asked me why i left my teaching profession and why i want to come in this field kindly give me the proper answer of this queston  1
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice) Subex1
Why does not use getgh(); and <conio.h> in c language. Elofic2
Which command is more efficient? *(ptr+1) or ptr[1]  3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com