ch16_01.cpp

来自「在文件中含有大量基础C program code以公初学者参考」· C++ 代码 · 共 31 行

CPP
31
字号
#include<iostream>
using namespace std;
template<class anyType>
anyType equation(anyType x)
{
    anyType y;
    y=x*x*x-3;
    return y;
}
int main()
{
    int i_ans;
    int i_x=10;
    i_ans=equation(i_x);
    cout<<"formua y=2(x*x)-3"<<endl;
    cout<<"int ans="<<i_ans<<endl;
    cout<<"----------------"<<endl;
    float f_ans;
    float f_x=3.3;
    f_ans=equation(f_x);
    cout<<"formula y=2(x*x)-3"<<endl;
    cout<<"float ans="<<f_ans<<endl;
    cout<<"----------------"<<endl;
    double d_ans;
    double d_x=9.23586784;
    d_ans=equation(d_x);
    cout<<"formula y=2(x*x)-3"<<endl;
    cout<<"double ans="<<d_ans<<endl<<endl;
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?