Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

sir i wanted to know how we wap in c to add numbers without
using arithmetic operator in which digits are entered by
user?

Answer Posted / niranjan vg

#include<stdio.h>

int main()
{
int a,b,sum,carry;
printf("\n Enter the numbers : ");
scanf("%d%d",&a,&b);
sum=a^b;
carry=a&b; // Produce a extra carry bit if present
while(carry!=0)
{
carry<<=1; // shift for every iteration so
that it gets added with the next digit
a=sum;
b=carry;
sum=a^b; // perform Xor Operation
carry=a&b; // Calculate the new value for carry
}
printf("\n The sum is %d", sum);
}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between far and near in c?

1066


Write the syntax and purpose of a switch statement in C.

1100


Can variables be declared anywhere in c?

1087


What does the function toupper() do?

1123


Explain how do you print an address?

1146


What is the code in while loop that returns the output of given code?

1985


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

995


What are global variables?

1181


What is the use of header files?

1105


What is the condition that is applied with ?: Operator?

1129


how should functions be apportioned among source files?

1099


What is the difference between struct and typedef struct in c?

1123


What does printf does?

1243


What is hashing in c language?

1304


What is the full form of getch?

1274