online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
// Sumar números enteros sin signo almacenados en cadenas // Agosto de 2009 Con Clase, Salvador Pozo #include <iostream> #include <cstring> using namespace std; const unsigned int cadmax = 32; typedef char numero[cadmax]; bool Sumar(numero, numero, numero); int max(int, int); int main() { numero n1="999999999999999999"; numero n2="1"; numero suma; Sumar(n1, n2, suma); cout << n1 << " + " << n2 << " = " << suma << endl; return 0; } bool Sumar(numero n1, numero n2, numero r) { // Primero, buscar los dígitos de la derecha: char c1,c2; int acarreo = 0; int lon1=strlen(n1); int lon2=strlen(n2); // Colocar el terminador de la cadena resultado: r[max(lon1, lon2)] = 0; // Hacer la suma, digito a digito: do { lon1--; lon2--; if(lon1 < 0) c1 = '0'; else c1 = n1[lon1]; if(lon2 < 0) c2 = '0'; else c2 = n2[lon2]; r[max(lon1, lon2)] = acarreo+c1+c2-'0'; if(r[max(lon1, lon2)] > '9') { r[max(lon1, lon2)]-=10; acarreo=1; } else acarreo = 0; } while(lon1 > 0 || lon2 > 0); // Desbordamiento: if(acarreo) { if(strlen(r) < cadmax) { for(int i=strlen(r)+1; i > 0; i--) r[i] = r[i-1]; r[0] = '1'; return false; } } return true; } int max(int a, int b) { if(a > b) return a; return b; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue