编辑代码

#include<iostream>
using namespace std;
int divideSquare(int length,int width)
{
	if(length<width||length<=0||width<=0)
	cout<<"error";
	if(length%width==0)
	return width;
	int smallwidth=length%width;
	return divideSquare(width,smallwidth);

 } 

 int divideSquareT(int length,int width)
{
	int smallwidth;
	if(length<width||length<=0||width<=0)
	cout<<"error";
	if(length%width==0)
	return width;
	while(length%width!=0)
    {
	smallwidth=length%width;
	length=width;
	width=smallwidth;
	return smallwidth;
    }
 } 
 int main(){
   int length =9,width=3;
   cout<<"农民递归分得正方形土地宽为"<<divideSquare(length,width)<<endl;
   cout<<"农民递推分得正方形土地宽为"<<divideSquareT(length,width)<<endl;
 }