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   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
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 ?    5 Yes 3 No
Selloorhari
 
  Re: How to add two numbers without using arithmetic operators?
Answer
# 2
Please explain me the code
 
Is This Answer Correct ?    1 Yes 0 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 ?    1 Yes 1 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 ?    0 Yes 2 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 ?    0 Yes 1 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 ?    1 Yes 3 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 2 No
Prashant
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is array? HCL6
what is the difference between normal variables and pointer variables.............. Satyam4
Which is not valid in C? 1) class aClass{public:int x;} 2) /* A comment */ 3) char x=12;  4
Which of the following is not an infinite loop ? a.while(1){ .... } b.for(;;){ ... } c.x=0; do{ /*x unaltered within theloop*/ ... }while(x==0); d.# define TRUE 0 ... while(TRUE){ .... } TCS4
how to convert binary to decimal and decimal to binary in C lanaguage  2
Can you think of a way when a program crashed before reaching main? If yes how?  2
what is the function of .h in #include<stdio.h> in c ? IBM4
write a C code to reverse a string using a recursive function, without swapping or using an extra memory. Motorola2
Write a programme to find even numbers without using any conditional statement? Infosys3
how to find sum of digits in C? CTS8
write a program to display the array elements in reverse order in c language  2
What is C language Terminator? TCS12
how does the C compiler interpret the following two statements p=p+x; q=q+y; a.p=p+x; q=q+y b.p=p+xq=q+y c.p=p+xq; q=q+y d.p=p+x/q=q+y TCS2
void main() { int i=5; printf("%d",i++ + ++i); } ME6
can you explain in brief what is "r+" mode in a file... i know that it si used to read and modify rhe existing content.... but explalanation about the file pointer in "r+" mode i wann to know??????????? Cognizent1
post new interiew question and aptitude test papers  1
how many times of error occur in C  7
int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output? Verifone11
What is difference between the following 2 lines…. int temp = (int)(0x00); int temp = (0x00int); Bosch3
What is structure padding ? HP1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

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