更新时间2018-03-06 21:31:26
class MathopsApp
{
static void Main(string[] args)
{
// The System.Pandom class is part of the .NET
// Framework class library. Its default constructor
// seeds the Next method using the current date/time.
Random rand = new Random();
int a, b, c;
a = rand.Next() % 100; // Limit max to 99.
b = rand.Next() % 100; // Limit max to 99.
Console.WriteLine("a={0} b={1}", a, b);
c = a * b;
Console.WriteLine("a * b = {0}, c");
// Note the following code uses integers. Therefore.
// if a is less than b, the result will always
// be 0. To get a more accurate result, you would
// nee to use variables of type double or float.
c = a / b;
Console.WriteLine("a / b = {0}", c);
c = a + b;
Console.WriteLine("a + b = {0}", c);
c = a - b;
Console.WriteLine("a - b = {0}", c);
c = a % b;
Console.WriteLine("a % b = {0}", c);
}
}
//定义一个类,名称是MathopsApp
class MathopsApp
{
//定义静态Main方法,作为执行入口,无返回值
//可接收一个字符串数组的参数args
static void Main(string[] args)
{
//定义并创建一个新的随机数生成器,未指定种子
Random rand = new Random();
//定义三个整型变量
int a, b, c;
//为a变量产生一个100以内的随机数并赋值
a = rand.Next() % 100; // Limit max to 99.
//为b变量产生一个100以内的随机数并赋值
b = rand.Next() % 100; // Limit max to 99.
//在控制台输出一行字符串
//假设随机数a为4,随机数b为6,则输入的字符串为“a=4 b=6”
Console.WriteLine("a={0} b={1}", a, b);
//计算a乘以b,并将结果赋值给变量c
c = a * b;
//在控制台输出一行字符串,“a * b = ” + a乘以b的结果
Console.WriteLine("a * b = {0}, c");
//计算a除以b,并将结果赋值给变量c
c = a / b;
//在控制台输出一行字符串,“a / b = ” + a除以b的结果
Console.WriteLine("a / b = {0}", c);
//计算a加b,并将结果赋值给变量c
c = a + b;
//在控制台输出一行字符串,“a + b = ” + a加b的结果
Console.WriteLine("a + b = {0}", c);
//计算a减b,并将结果赋值给变量c
c = a - b;
//在控制台输出一行字符串,“a - b = ” + a减b的结果
Console.WriteLine("a - b = {0}", c);
//计算a整除b,并将结果赋值给变量c
c = a % b;
//在控制台输出一行字符串,“a % b = ” + a整除b的结果
Console.WriteLine("a % b = {0}", c);
}
}
这个就是一个产生随机的+-*/算术式的C#程序.上面关键部分已有详细的说明了(只是英文的,个人观点是真正程序员必须有英文基础的)
你是哪个部分没有看明白?可以追问
上一篇:jquery内置排序是什么
下一篇:哪位大佬帮助讲解一下这个代码