#include <iostream>
#include<cmath>
using namespace std;
float cot(float tmp) //华氏度转化为摄氏度
{
float c;
c = (tmp - 32) * 5 / 9;
return c;
}
void maxl(int a,int b) { //重载函数
int max;
max = a > b ? a : b;
return max;
}
void maxl(int a, int b, int c) {
int max;
max = a > b ? a : b;
max = max > c ? max : c;
return max;
}
void maxl(double a, double b) {
double max;
max = a > b ? a : b;
return max;
}
void maxl(double a, double b, double c) {
double max;
max = a > b ? a : b;
max = max > c ? max : c;
return max;
}
int fib(int n) {
if(n>2)
return fib(n - 1) + fib(n - 2); //递归方法
if (n == 1 || n == 2)
return 1;
}
int main(float x,float y) {
cin >> x, y;
cout << pow(x, y);
float a,b;
cin >> a;
b = cot(a);
cout << b;
int n, answer;
cin >> n;
answer = fib(n);
cout << answer << "is the" << n << "the fibonacci number";
return 0;
}
总结
一、重载函数
(1)重载函数应该在形参数量或形参类型上有所不同
(2)main函数不能重载
(3)只有返回类型不同不算重载
二 ,平方函数
(1) c++中平方函数为pow(a,b),a为平方的数,b为几次方
(2 pow的头文件是#include<cmath>
(3) pow(a,b)中的a,b都为浮点数,返回值也是浮点数