| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools |
Rating:
|
Display Modes |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Feb 2008
Posts: 25
Thanks: 3 Thanked 2 Times in 2 Posts Thanks: 3
Thanked 2 Times in 2 Posts
Rep Power: 1
|
how to add two numbers without using arithmetic and unary operators......
how to add two numbers without using arithmetic and unary operators......
|
|
|
|
|
|
#3 (permalink) |
|
Super Moderator
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117 Thanked 241 Times in 198 Posts Thanks: 117
Thanked 241 Times in 198 Posts
Blog Entries: 4
Rep Power: 51
|
Re: how to add two numbers without using arithmetic and unary operators......
Code:
#include <stdio.h>
int add(int a, int b){
if (!a) return b;
else
return add((a & b) << 1, a ^ b);
}
int main(){
int a,b;
printf("Enter the two numbers: \n");
scanf("%d",&a);
scanf("%d",&b);
printf("Sum is: %d",add(a,b));
}
__________________
Give 1 cup rice to a hungry Indian just by a mouse click. No money, no form filling, no hassle... Click here for the donation. |
|
|
|
| The Following User Says Thank You to sk_kireeti For This Useful Post: |
bharathi chowdary (30-06-08)
|
|
|
#4 (permalink) |
|
Junior Member
Join Date: Apr 2008
Location: Pune
Age: 25
Posts: 8
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
|
Re: how to add two numbers without using arithmetic and unary operators......
we have the function Add in c and c++ just include the Math.h file.....
and use the function....... |
|
|
|
|
|
#5 (permalink) |
|
Junior Member
Join Date: Jul 2008
Posts: 1
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
|
Re: how to add two numbers without using arithmetic and unary operators......
Hi,
This is fine for int values. But it is not working for float/double values. how to do for that values. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|