第43课 最大公约数 动动脑 第2题《小学生C++趣味编程》

#include<iostream> 
using namespace std;
int main()
{
	int x,y,temp,ans;
	cin>>x>>y;//28 7
	
	if( x<y)
	{
		temp=x;
		x=y;
		y=temp;
	}
	
	while( x != y)//28 7
	{
		x-=y;//21 
		if( x<y)
		{
			temp=x;
			x=y;
			y=temp;
		}
	}
	
	ans=x;
	
	cout<<ans<<endl;
	
	return 0; 
}
/*
输入:28 7
输出:__________ 
*/

 

 

Supongo que te gusta

Origin blog.csdn.net/dllglvzhenfeng/article/details/121885083
Recomendado
Clasificación