墨鱼丸


私信TA

用户名:qianysm

访问量:3448

签 名:

等  级
排  名 11004
经  验 1000
参赛次数 0
文章发表 6
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:
用if,else
注意事项:
else后面不加条件
参考代码:

#include<iostream>

using namespace std;


int main()

{

    int x;

    cin >> x;

    if(x<1)

    {

        cout << x;

    }

    else if(1<=x && x<10)

    {

        cout << 2*x-1;

    }

    else

    {

        cout << 3*x-11;

    }

    return 0;

}

1008.png1008.png


解题思路:

用if,else

注意事项:

else后面不加条件,第一个代码设了y,第二个没设

参考代码2:

#include<iostream>

using namespace std;


int main()

{

int x,y;

cin >> x;

if(x<1)

{

y=x;

cout << y;

}

else if(x>=1 && x<10)

{

y=2*x-1;

cout << x;

}

else

{

y=3*x-11;

cout << y;

}

return 0;

}

 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

是不是写错了
2022-06-28 10:47:20
  • «
  • 1
  • »