how to add numbers with out using any arthematic operators in c
pavankumar77 0 Newbie Poster
Recommended Answers
Jump to Posttry:
int sum(int num1,int num2) { for(int i=0;i<num2;i++) num1++; return num1; }
Jump to PostNot a good way :( but it works fine.
int sum(int num1, int num2) { int total, temp, temptotal; total = num1 ^ num2; for(temp = num1 & num2; temp != 0; temp = temptotal & temp) { temptotal = total; total = total ^ (temp = …
Jump to Post#include <iostream> unsigned int addone(unsigned int x) { unsigned int y = 0; unsigned int z = 0; for (int i = 0; i <= 31; ++i) { z = (x<<(31 - i))>>31<<(i); if (z > 0) { x = x ^ z; } else { y …
Jump to Postgerard4143, you're still using operator (-)
Whoops...busted
and the ++ operator in the for statement
Jump to Post@Gourav_4: That looks like Javascript, not C. You are using the minus (arithmetic) operator, so the answer is invalid.
All 20 Replies
DangerDev 107 Posting Pro in Training
Aia 1,977 Nearly a Posting Maven
Dave Sinkula 2,398 long time no c Team Colleague
invisal 381 Search and Destroy
gerard4143 commented: awesome code +1
Narue 5,707 Bad Cop Team Colleague
invisal 381 Search and Destroy
Aia 1,977 Nearly a Posting Maven
Dave Sinkula 2,398 long time no c Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Aia 1,977 Nearly a Posting Maven
Narue 5,707 Bad Cop Team Colleague
Aia 1,977 Nearly a Posting Maven
Dave Sinkula 2,398 long time no c Team Colleague
gerard4143 371 Nearly a Posting Maven
joshSCH commented: Pay attention. -2
Aia 1,977 Nearly a Posting Maven
invisal 381 Search and Destroy
gerard4143 371 Nearly a Posting Maven
Anuj Verma 0 Newbie Poster
Gourav_4 0 Newbie Poster
pritaeas 2,211 ¯\_(ツ)_/¯ Moderator Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.