struct BigNumber { int * digitos; int size; bool pos; BigNumber() { digitos = new int[1]; digitos [0] = 0; size = 1; pos = true; } int Compare(BigNumber b) { if(pos && !b.pos) return 1; if(!pos && b.pos) return -1; if(size > b.size) return 1; else if(b.size > size) return -1; for(int i = size-1; i >= 0; i--) { if(digitos[i]>b.digitos[i]) { if(pos) return 1; else return -1; } else if(b.digitos[i] > digitos[i]) { if( pos) return -1; else return 1; } } return 0; } void input() { string n1, n2, op; while (true) { cout << "1st #? "; cin >> n1; cout<< "2nd #? "; cin >> n2; cout << "Operation? "; cin >> op; BigNumber a,b; a.set(n1); b.set(n2); if (op == "+") { if (a.pos && b.pos) a.Add(b); else if (a.pos) a.Subtract(b); else if (b.pos) b.Subtract(a); else a.Add(b); } //both are negative if (op == "-") { if (a.pos && b.pos) a.Subtract(b); else if (a.pos) a.Add(b); else if (b.pos) { a.Add(b); a.pos = false;} else { a.Subtract(b); a.pos = !a.pos;} } if (op == "*") { int B = toInt(n2); a.Multiply(B); } if (op == "/") { int B = toInt(n2); a.Divide(B); } if (op == "!") { a.Factorial(toInt(n1)); } if (op == "Compare") { a.Compare(b); } a.print(); cout << "\n";} } void main() { input(); }
struct
digitos
size
pos
void
System.Numerics.BigInteger
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)