1162 Problem K 《C语言程序设计》江宝钏主编-习题4-2-分段函数

问题描述

编写程序,输入x,输出y
y= x2+3x-4 (x≤5)
=X2-5x+7 (x>5)

输入

一个整数x

输出

对应的y

样例输入

5

样例输出

36

AC代码

#include <iostream>
using namespace std;

int main()
{
    int x,y;
    cin >> x;
    if(x <= 5)
    {
        y = x*x + 3*x -4;
    }
    else
    {
        y = x*x - 5*x + 7;
    }
    cout << y << endl;
    return 0;
}
发布了119 篇原创文章 · 获赞 28 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_41179709/article/details/103956638
今日推荐