c++打卡练习(31)

发布时间 2023-05-16 16:43:34作者: 夏季彼岸德

求两个整数的最大公因数

流程图:
伪代码:

源代码:

#include<iostream>
using namespace std;
int main(){
int x,y,i,k;
cout<<"请输入两个整数"<<endl;
cin>>x;
cin>>y;
if(x<y){
int t;
t=x;
x=y;
y=t;
}
for(i=y;i>=1;i--){
if(x%i==0&&y%i==0){
k=i;
cout<<k<<endl;
break;
}
}
return 0;
}