编写一个程序,递归调用成员函数,输出最大公约数
#include<iostream>
using namespace std;
class gcd_class
{
public:
gcd_class(int p,int q);
long func(int j,int k);
private:
int n;
int d;
};
gcd_class::gcd_class(int p,int q)
{
n=p;
d=q;
}
long gcd_class::func(int j,int k)
{
if(k==0)
return j;
else return(k,j%k);
}
class derived:public gcd_class
{
protected:
char *c;
public:
derived(char *m):gcd_class(1,1)
{
c=m;
}
long pfunc(int l,int r)
{
return gcd_class::func(l,r);
}
};
int main()
{
derived A("output n!\n");
int n,d;
cout<<"please input two int :";
cin>>n>>d;
cout<<"gcd("<<n<<","<<d<<")="<<A.pfunc(n,d)<<endl;
return 0;
}
团子小代码
不务正业的团团分享小语录时刻~~
“北斗星每夜路过,闪烁她的疑惑
夜啊, 分明长满了星星晚风
可她们却给你 取名字叫天空。”
摘选自《玫瑰与小鹿》