作业补做2

来源:互联网 发布:房屋设计软件下载 编辑:程序博客网 时间:2024/05/01 01:10
//用“辗转相除方法”计算两个数 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;      }   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();}




0 0
原创粉丝点击