C++编写重载函数

来源:百度知道 编辑:UC知道 时间:2024/06/06 09:05:08
编写重载函数f1,完成:
参数为两个int型,返回余数;
参数为两个double型,返回两数之和;
参数为两个字符型,则直接输出此两个字符,无返回值

#include <iostream>
using namespace std;

int f1(int,int);
double f1(double,double);
void f1(char,char);

int main()
{
cout<<f1(14,6)<<endl;
cout<<f1(5.6,6.5)<<endl;
f1('m','n');
return 0;
}
int f1(int a,int b)
{
return (a>b ? a%b : b%a);
}
double f1(double c,double d)
{
return c+d;
}
void f1(char ch1,char ch2)
{
cout<<ch1<<"\t"<<ch2<<endl;
}

int f1(int a, int b)
{
return ((a > b) ? (a % b) : (b % a));
}

double f1(double a, double b)
{
return a + b;
}

void f1(char a, char b)
{
printf("%c %c", a, b);
}

太汗了 哪本书上都有这样的例子吧

#include<stdio.h>
int f1(int int);
double f1(double double);
void f1(char char);
void main()
{ int a,b;
f