第八节 运算符和表达式
先来看下吉姆拉尔森公式求星期几的问题。这里面包含了多种运算符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace yunsuanfu
{
class Program
{
static void Main(string[] args)
{
int y=2008;
int m=8;
int d=8;
int week=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7;
Console.WriteLine("2008年8月8日是星期:{0}", week);
}
}
}
运算符如下图

一。/
int n=5/2;
二。取余运算 %.求两个数的余数。 5%2
三。代数运算
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace daishu
{
class Program
{
static void Main(string[] args)
{
int x;
int y;
Console.Write("x=");
x = Convert.ToInt32(Console.ReadLine());
y = x * x * x + 3 * x * x - 24 * x + 30;
Console.WriteLine(y);
}
}
}
Math类中的常见函数如下图

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace suanshu
{
class Program
{
static void Main(string[] args)
{
int a = 9;
Console.WriteLine(Math.Sqrt(9));
Console.WriteLine(Math.Abs(9));
}
}
}
浙公网安备 33010602011771号