//test6 用“辗转相除方法”计算两个数 x,y 的最大公约数
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
void writeinfile(int n);
void main()
{
int x,y,n;
x=25,y=10;
/**********Program**********/
int temp,r;
if(y<x)
{ temp=y;
y=x;
x=temp;
//(把大数放在y中,小数放在x中)
}
while(x!=0)
{ r=y%x;
y=x;
x=r;
}
/********** End **********/
cout<<y;
writeinfile(y);
}
void writeinfile(int n)
{
fstream myfile;
myfile.open(" f.txt" ,ios::out);
myfile<<n<<endl;
myfile.close();
}
补、C++第九次上机实验
猜你喜欢
转载自blog.csdn.net/qq_34143673/article/details/51700660
今日推荐
周排行