C# 流程控制语句的实现
用if….else if…..else编程实现。输入x,求y。
x<1时: y=2*x-5
1<=x<=10时:y=2*x
x>=10时:y=2*x+5
实现代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace work1
{
class Program
{
static void Main(string[] args){
int y = 0;
int x = int.Parse(Console.ReadLine());
if (x < 1)
y = 2 * x - 5;
else if (x >= 1 && x <= 10)
y = 2*x;
else
y = 2*x + 5;
Console.WriteLine(y);
}
}
}