编辑代码

#include <stdio.h>

//递归
int dividetoSquare(int lenght,int width){
    if(lenght % width == 0){
        return width;
    }

    return dividetoSquare(width, lenght%width);
}

//递推  迭代的方式
int dividetoSquareIter(int lenght,int width){
    int w = lenght % width;

    while(w > 0){
        lenght = width;
        width = w;
        w = lenght % width;
    }

    return width;
}

int main () {
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
    //printf("Hello world!     - c.jsrun.net.");
    printf("%d\n",dividetoSquare(1680,640));
    printf("%d\n",dividetoSquareIter(1680,640));
    return 0;
}