c#类相关的编程题 高手求解
1个回答
展开全部
//第3题
using System;
public class Test
{
public static void Main(string[] args)
{
Calculator cl=new Calculator();
string[] strs;
float a,b;
Console.Write("请在一行中输入两个数,以空格分隔:");
strs=System.Text.RegularExpressions.Regex.Split(Console.ReadLine().Trim(),"\\s+");
if(strs.Length>=2)
{
a=Single.Parse(strs[0]);
b=Single.Parse(strs[1]);
Console.WriteLine("{0}+{1}={2}",a,b,cl.He(a,b));
Console.WriteLine("{0}/{1}={2}",a,b,cl.Shang(a,b));
Console.WriteLine("{0}*{1}={2}",a,b,cl.Ji(a,b));
Console.WriteLine("{0}-{1}={2}",a,b,cl.Cha(a,b));
}
Console.Write("Press any key to continue . . . ");
Console.ReadLine();
}
}
class Calculator
{
public float He(float a,float b)
{
return a+b;
}
public float Shang(float a,float b)
{
return a/b;
}
public float Ji(float a,float b)
{
return a*b;
}
public float Cha(float a,float b)
{
return a-b;
}
}
//第4题
using System;
public class Test
{
public static void Main(string[] args)
{
Console.WriteLine("5!={0}",Fac.Factorial(5));
Console.Write("Press any key to continue . . . ");
Console.ReadLine();
}
}
class Fac
{
public static ulong Factorial(uint n)
{
ulong r=1;
while(n>0)
r*=n--;
return r;
}
}
using System;
public class Test
{
public static void Main(string[] args)
{
Calculator cl=new Calculator();
string[] strs;
float a,b;
Console.Write("请在一行中输入两个数,以空格分隔:");
strs=System.Text.RegularExpressions.Regex.Split(Console.ReadLine().Trim(),"\\s+");
if(strs.Length>=2)
{
a=Single.Parse(strs[0]);
b=Single.Parse(strs[1]);
Console.WriteLine("{0}+{1}={2}",a,b,cl.He(a,b));
Console.WriteLine("{0}/{1}={2}",a,b,cl.Shang(a,b));
Console.WriteLine("{0}*{1}={2}",a,b,cl.Ji(a,b));
Console.WriteLine("{0}-{1}={2}",a,b,cl.Cha(a,b));
}
Console.Write("Press any key to continue . . . ");
Console.ReadLine();
}
}
class Calculator
{
public float He(float a,float b)
{
return a+b;
}
public float Shang(float a,float b)
{
return a/b;
}
public float Ji(float a,float b)
{
return a*b;
}
public float Cha(float a,float b)
{
return a-b;
}
}
//第4题
using System;
public class Test
{
public static void Main(string[] args)
{
Console.WriteLine("5!={0}",Fac.Factorial(5));
Console.Write("Press any key to continue . . . ");
Console.ReadLine();
}
}
class Fac
{
public static ulong Factorial(uint n)
{
ulong r=1;
while(n>0)
r*=n--;
return r;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询