第十九天第一个问题

问题描述:

请使用模板参数设计实现双倍功能函数,函数功能要求实现返回值为输入参数的两倍,函数参数应能适应整型、浮点型、双精度型等各种类型,返回值类型与参数一样。

裁判测试程序样例:

 
#include <iostream>
using namespace std;

/*请在这里填写答案*/

int main(void){
    char c='\0';
    int i=0;
    long l=0;
    scanf("%c%d%ld",&c,&i,&l);
    cout<<Double(c)<<endl;
    cout<<Double(i)<<endl;
    cout<<Double(l)<<endl;
    float f=1.1;
    double d=2.2;
    scanf("%f%lf",&f,&d);
    cout<<Double(f)<<endl;
    cout<<Double(d)<<endl;
    return 0;
}
 

输入样例:

0
1
200000
3.45
6.789
 

输出样例:

`
2
400000
6.9
13.578
代码:

template <class a>
a Double(a &b)
{
a x;
x=2*b;
return x;
}

posted @ 2023-05-11 20:25  序章0  阅读(25)  评论(0)    收藏  举报