---
# System prepended metadata

title: Untitled

---

# 
```cpp=
void division(int dividend[], int divisor[], int quotient[], int remainder[],
    int dividendDegree, int divisorDegree, int& quotientDegree, int& remainderDegree)
{
    if (isZero(dividend, dividendDegree))
    {
        quotientDegree = 0;
        quotient[0] = 0;

        remainderDegree = 0;
        remainder[0] = 0;
        return;
    }

    //&quotientDegree餘數(固定值)
    quotientDegree = dividendDegree - divisorDegree;

    //被除數存入餘數做計算
    for (int i = 0; i < arraySize; i++)
    {
        remainder[i] = dividend[i];
    }
    remainderDegree = dividendDegree;
    //計算

    while (remainderDegree >= divisorDegree) //當餘數degree小於除數Degree跳出迴圈 (remainderDegree11 8 7 卡在9)
    {
        int i = remainderDegree - divisorDegree; //目前要計算商的位置
        quotient[i] = remainder[remainderDegree] / divisor[divisorDegree]; //算出當前位置的商
        //算當前buffer
        int buffer2[arraySize] = {};
        int bufferDegree2 = 0;
        //取當前的商
        int currentquotient[arraySize] = {};
        currentquotient[i] = quotient[i];
        multiplication(divisor, currentquotient, buffer2,
            divisorDegree, i, bufferDegree2);
        //算餘數
        subtraction(remainder, buffer2, remainderDegree, bufferDegree2);

        //餘數為0跳出迴圈
        if (remainderDegree == 0 && remainder[0] == 0)
        {
            break;
        }
        //餘數Degree = 除數Degree = 0 且 餘數<除數 跳出迴圈
        if (remainderDegree == 0 && divisorDegree == 0 && remainder[0] < divisor[0])
        {
            break;
        }
    }

    if (quotientDegree != 0 && quotient[quotientDegree] == 0) //有bug
        cout << "Leading coefficient of quotient cannot be zero!\n";

    if (remainderDegree != 0 && remainder[remainderDegree] == 0)
        cout << "Leading coefficient of remainder cannot be zero!\n";
}
```