算术运算符

在C#中有5个算术运算符:+   -   *    /    %

1,是二元运算 并且要求参与运算的2个数值的类型相同并且经过运算后的结果与与操作数的类型也必须相同.

2,在算术表达式中如果要改变运算的优先级可以用小括号,小括号可以无限制的套用但一定要成对出现.

示例一:三科成绩之总和、平均分

int chinese=90,math=80,english=91;

int total=chinese+math+english;

int mean=total/3;

Console.WriteLine("总成绩={0} \n 平均成绩={1}",total,mean);

Console.ReadKey();

 

示例二:2数之总和

int number1=10,number2=20;

int total=number1+number2;

Console.WriteLine("总和={0}",total);

Console.ReadKey();

示例三:求圆的面积

double pi=3.14,r=5.0;

double area=r*r*pi;

Console.WriteLine("面积={0}",area);

Console.ReadKey();

 

示例四:总价+打折价

double tshirtPrice=35,trousersPrice=120;

double totalMoney=tshirtPrice*3+trousersPrice*2;

double discount=totalMoney*0.88;

Console.WriteLine("购物总计:{0}\n{1}",totalMoney,discount);

Console.ReadKey();

 

posted @ 2016-04-04 21:59  思维乐趣  阅读(222)  评论(0编辑  收藏  举报