码迷,mamicode.com
首页 > 其他好文 > 详细

11.算术运算符

时间:2016-10-26 11:19:21      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:计算   技术   运算   半径   void   blog   学生   png   border   

+,-,*,/,%

我们在使用算术运算符的时候,一定要注意算术运算符的优先级的问题.

代码示例1:
  1. namespace _12.算术运算符
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //演示:某学生三门课的成绩为:语文:90分,数学100,英语80,请计算它的总成绩和平均成绩.
  8. int chinese = 90;
  9. int math = 100;
  10. int english = 80;
  11. Console.WriteLine("总成绩为:{0},平均成绩为:{1}.",chinese+math+english,(chinese+math+english)/3);
  12. Console.ReadKey();
  13. }
  14. }
  15. }
技术分享
 
代码示例2:
  1. namespace _13.算术运算符练习题01
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //定义两个数分别为100和20打印两个数的和.
  8. int a = 100;
  9. int b = 20;
  10. Console.WriteLine("和为:{0}",a+b);
  11. Console.ReadKey();
  12. }
  13. }
  14. }
技术分享
 代码示例3:
  1. namespace _13.算术运算符练习题02
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //计算半径为5的圆的面积和周长并打印出来,(pi为3.14)
  8. const double PI = 3.14; //圆周率
  9. int r = 5; //半径为5
  10. Console.WriteLine("周长为:{0}", 2 * PI * r);
  11. Console.WriteLine("面积为:{0}",PI*r*r);
  12. Console.ReadKey();
  13. }
  14. }
  15. }
技术分享
代码示例4:
  1. namespace _13.算术运算符的练习题03
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //某商店T桖的价格为35元/件,裤子的价格为120元/条,小明在该店
  8. //买了3键T恤和2条裤子,请计算小明应付多少钱.
  9. int T_shirt = 35;
  10. int trousers = 120;
  11. Console.WriteLine("三件T恤和两件裤子的价格为:{0}",25*3+120*2);
  12. Console.WriteLine("以上价格打8.8折之后的价格为:{0}",(25 * 3 + 120 * 2)*88/100);
  13. Console.ReadKey();
  14. }
  15. }
  16. }

技术分享
 
 





11.算术运算符

标签:计算   技术   运算   半径   void   blog   学生   png   border   

原文地址:http://www.cnblogs.com/HelloZyjS/p/5999578.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!