Given two integers A and B, find their exact sum.
This time there are no limitations on A and B (of course, they will fit in memory).
Im stuck on this question and really need to know how to do it.
Need Fast Help
Started by JP16.1470, Nov 12 2008 06:57 PM
14 replies to this topic
#1
Posted 12 November 2008 - 06:57 PM
|
|
|
#2
Posted 12 November 2008 - 07:17 PM
what do you mean by exact sum?
if its like normal one just declare three variables two for input and one for answer
if its like normal one just declare three variables two for input and one for answer
#3
Posted 12 November 2008 - 08:09 PM
#4
Posted 12 November 2008 - 10:05 PM
aeresnaa would you show an example please!! because i dont know how i could do tht. Thx
#5
Posted 12 November 2008 - 10:41 PM
#include <iostream>
using namespace std;
int main()
{
int a, b;
float c = (a + b);
cin << a;
cout << "\n";
cin << b;
cout << c;
return 0;
}
Is this what you want? Edited.
Edited by nullbyte, 12 November 2008 - 11:21 PM.
#7
Posted 13 November 2008 - 05:50 AM
We don't do homework for people. The phrase "exact sum" implies something other than the standard result for addition, but it's not clear how.
#9
Posted 13 November 2008 - 10:12 AM
it does mean bignum.
#10
Posted 13 November 2008 - 10:27 AM
Input strings, then convert each digit into a number, then add them right to left, making sure to divide to catch the digit carry.
"12345" + "0492513": '3'-'0' = 3 (int) '5'-'0' = 5 (int) 3-5 = 8 '0' + 8 = '8' (char) EXAMPLE: "9" + "13" extend to make them the same length --> "09"+"13" start from right end: int digitA = '3' - '0'; //cheap conversion trick int digitB = '9' - '0'; int carry = (digitA + digitB) / 10; //get overflow int digitResult = (digitA + digitB) % 10; char chResult = (char)digitResult + '0';
#12
Posted 13 November 2008 - 04:06 PM
Try pseudocode first, then clear code, then optimize. You'll get fewer bugs that way, at least in my experience.


Sign In
Create Account

Back to top









