Name: A times B equals F 2011-02-03 9:51
Why doesn't this work? ='[
//Set up nested loops:
for(int i = 0; i < 3; ++i)
{
for(int j = 0; j < 3; ++j)
{
//Multiply elements of A * B = C:
C[j] = A[i] * B[j];
//Deal with Carry of multiplication:
if(C[j] > 9)
C[j+1] += CarryTheOne( C[j] );
//Add to contiguous answer:
F[j+i] += C[j];
//Deal with Carry of addition:
F[j+i+1] += CarryTheOne( F[j+i] );
}
}
//--------------------------
int CarryTheOne( int & x )
{
if(x > 9)
{
//get unit element ( < 9 )
x -= 10;
//return carry (only ever 1)
return 1;
}
return 0;
}
//Set up nested loops:
for(int i = 0; i < 3; ++i)
{
for(int j = 0; j < 3; ++j)
{
//Multiply elements of A * B = C:
C[j] = A[i] * B[j];
//Deal with Carry of multiplication:
if(C[j] > 9)
C[j+1] += CarryTheOne( C[j] );
//Add to contiguous answer:
F[j+i] += C[j];
//Deal with Carry of addition:
F[j+i+1] += CarryTheOne( F[j+i] );
}
}
//--------------------------
int CarryTheOne( int & x )
{
if(x > 9)
{
//get unit element ( < 9 )
x -= 10;
//return carry (only ever 1)
return 1;
}
return 0;
}