計算一個分段函數
using System;
namespace 分段函數
{
class Program
{
static void Main(string[] args)
{
Console.Write ("請輸入一個數:");
double y=0;
double x = Convert.ToDouble(Console.ReadLine());
if(x>6)
{
y=5*(x*x+4*x-6)/27;
}
if(x>=6 && x<0)
{
y = Math.Log(16) / Math.Log(3)+x;
}
if(x<=0)
{
y = 23 * Math.Abs(x * x * x + 4) / 7;
}
string n = y.ToString("f2");
Console.WriteLine("y ={0}", n);
}
}
}