首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

小鸟的小东东,大家给点建议解决方法

2012-03-06 
小鸟的小东东,大家给点建议怎么写都觉得是C。。。郁闷中,大家看看给点建议哈/******************************

小鸟的小东东,大家给点建议
怎么写都觉得是C。。。郁闷中,大家看看给点建议哈
/****************************************************
copyright   (c)   2007   05
Date:   2007   05   17
author:Hydra
start   time:21:41
end   time:22.02
subject:整数x和y的最大公约数是x和y都能整除的最大整数。
编写一个归函数gcd,令其返回x和y的最大公约数。x和y的
gcd函数的递归定义如下:如果y   等于0,那么gcd(x,y)就等于
x:否则gcd(x,y)就等于gcd(y,x%y),这里的%是求模运算符。

总结:练习输入输出流,这里,cin与cout为对象,cin的
get()方法可以接收单个字符输入,与c中getch()类似。
****************************************************/

#include   "stdafx.h "
#include   <iostream>

using   namespace   std;

int   gcd(int   aX,int   aY);

int   _tmain(int   argc,   _TCHAR*   argv[])
{
int   x   =   0;
int   y   =   0;
int   resultGCD   =   0;

cout   < <   "this   is   a   programmge   to   find   the   greatest   common   denominator   of   two   integer "   < <   endl;
cout   < <   "now   please   enter   the   first   integer: ";
cin   > >   x;
cout   < < "ok,   now   please   enter   the   second   integer: ";
cin   > >   y;

resultGCD   =   gcd(x,y);

cout   < <   "the   GCD   of   "   < <   x   < <   "   and   "   < <   y   < <   "   is   "   < <   resultGCD   < <   endl;

cout   < <   "press   any   key   to   continue... ";

cin.get();//接收输入第二个数后的回车
cin.get();//接收any   key以退出

return   0;
}

/****************************************************
fname:gcd
fPl:int   aX,int   aY
fRV:int
****************************************************/

int   gcd(int   aX,int   aY)
{
if(0   ==   aY)
{
return   aX;
}
else
{
gcd(aY,aX   %   aY);
}
}

[解决办法]
不要为C++而C++。对这么简单的问题,C/C++/java/C#的代码都很像,又有什么关系呢。

热点排行