YTU 2871: 复合函数求值

版权声明:转载请附上原文链接哟! https://blog.csdn.net/weixin_44170305/article/details/90172716

不恋尘世浮华,不写红尘纷扰,不叹世道苍凉,不惹情思哀怨,闲看花开,静待花落,冷暖自知,干净如始。

题目描述

求复合函数F(G(x)),其中函数F(x)=|x+1|,函数G(x)=3x3+2x2。要求编写函数funF()和funG()分别求F(x)和G(x),其余功能在main()中实现。补充完整下面的程序,并全部提交。

提交之后才知道为什么要让全部提交了吧。

#include<iostream>
#include<iomanip>
using namespace std;
double funF(double x);
double funG(double x);
int main()
{
    int x;
    cin>>x;
    cout<<setiosflags(ios::fixed)<<setprecision(3)<<funF(funG(x))<<endl;
    return 0;
}

输入

一个浮点数x

输出

输出复合函数的值,结果保留3位小数。输出占一行。

样例输入

copy

10.2

样例输出

3392.704
#include<iostream>
#include<iomanip>
using namespace std;
double funF(double x);
double funG(double x);
int main()
{
    double x;//看这里看这里
    cin>>x;
    cout<<setiosflags(ios::fixed)<<setprecision(3)<<funF(funG(x))<<endl;
    return 0;
}
double funF(double x)
{
    double y;
    if(x>=-1)
        y=x+1;
    else
        y=(-1-x);
        return y;
}
double funG(double x)
{
    double y;
    y=(3*x*x*x+2*x*x);
    return y;
}

猜你喜欢

转载自blog.csdn.net/weixin_44170305/article/details/90172716