您的位置:首页 > 编程语言 > C语言/C++

c++(补)

2016-06-17 16:21 393 查看
//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();  
}  

//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();
}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: