ACMNO.4有一个函数 写一段程序,输入x,输出y 输入 一个数x 输出 一个

版权声明:转载请声明原文链接地址,谢谢! https://blog.csdn.net/weixin_42859280/article/details/84874388

题目描述

有一个函数

y={ x      x<1
    | 2x-1   1<=x<10
    |3x-11  x>=10

写一段程序,输入x,输出y

输入

一个数x

输出

一个数y

样例输入

14

样例输出

31

提示

使用函数

来源/分类
C语言
在这里插入图片描述
思路:

输入一个数进行判断即可!

代码:

#include<iostream>
 using namespace std;
 int main()
 {
 	int a;
 	cin>>a;
 	if(a<1)
 	cout<<a;
 	if(a<10&&a>=1)
 	cout<<2*a-1;
 	if(a>=10)
 	cout<<a*3-11;
}

代码截图:
在这里插入图片描述
执行结果:
在这里插入图片描述提交结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42859280/article/details/84874388