1 数的交换:
C++中用类的成员函数实现俩个数的交换!
#include <iostream>
using namespace std;
class exchange
{
private:
int a;
int b;
public:
void intputnumber(int a,int b);
void exchangenumber();
void outputresult();
};
void exchange::inputnumber(int m,int n)
{
a=m;
b=n;
}
void exchange::exchangenumber()
{
int c;
c=a;
a=b;
b=c;
}
void exchange::outputresult()
{
cout<<"a="<<a<<" "<<"b="<<b<<endl;
}
int main()
{
exchange IntExchange;
IntExchange.inputnumber(3,5);
IntExchange.exchangenumber();
IntExchange.outputresult();
return 0;
}
还有
a = a^b
b = a^b
a = a^b
或
a=a+b
b=a-b
a=a-b
2求最大公约数和最小公倍数
阶乘
最佳答案
#include <stdio.h>
|