首页 输入两个数相加相减相乘相除并显示结果

输入两个数相加相减相乘相除并显示结果

举报
开通vip

输入两个数相加相减相乘相除并显示结果输入两个数相加相减相乘相除并显示结果 int a, b; Console.Write("输入第一个整数:"); a = Convert.ToInt32(Console.ReadLine()); Console.Write("输入第二个整数:"); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("相加为:{0} 相乘为:{1}", a + b, a * b); Console.WriteLine("相减为:{0} 相除为:{1}", a ...

输入两个数相加相减相乘相除并显示结果
输入两个数相加相减相乘相除并显示结果 int a, b; Console.Write("输入第一个整数:"); a = Convert.ToInt32(Console.ReadLine()); Console.Write("输入第二个整数:"); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("相加为:{0} 相乘为:{1}", a + b, a * b); Console.WriteLine("相减为:{0} 相除为:{1}", a - b, a / b); 输入半径和高,程序求出圆锥的体积 int r,h; Console.Write("请输入圆锥半径:"); r=Convert .ToInt32(Console .ReadLine()); Console.Write("请输入圆锥高:"); h=Convert.ToInt32(Console.ReadLine()); const double PI = 3.1415926; Console.WriteLine("圆锥的面积为:{0}",(PI * r * r*h)/3); Console.ReadLine(); 输入一个学生的多个信息,如姓名,年龄,性别,男、女,,C#课程成绩,并输出 string name; int age; char sex; double g; Console.Write("输入姓名:"); name = Console.ReadLine(); Console.Write("输入性别:"); sex = Convert.ToChar(Console.ReadLine()); Console.Write("输入年龄:"); age = Convert .ToInt32(Console.ReadLine()); Console.Write("输入C#课程成绩:"); g = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("姓名:{0} 性别:{1} 年龄:{2} C#课程成绩:{3}",name,sex,age,g); Console.ReadLine(); 练习三元运算符。编写控制台应用程序,程序功能是:输出任意两数中较大的一个数。 int n1, n2, t; Console.Write("请输入第一个数:"); n1 = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入第二个数:"); n2 = Convert.ToInt32(Console.ReadLine()); t = n1 > n2 ? n1 : n2; Console.WriteLine("较大的数是{0}",t); Console.ReadLine(); double applePrice,bananaPrice,appleWeiget,bananaWeiget,total; 用户输入苹果和香蕉的重量,程序自动完成付款数。 Console.Write("请输入苹果重量(kg):"); appleWeiget = Convert.ToDouble(Console.ReadLine()); Console.Write("请输入香蕉重量(kg):"); bananaWeiget = Convert.ToDouble(Console.ReadLine()); applePrice = 3.5; bananaPrice = 1.5; total = applePrice * appleWeiget + bananaPrice * bananaWeiget; Console.WriteLine("应付款为{0}", total); Console.ReadLine(); 第五章person类 青年老年中年类 using System; using System.Collections.Generic; using System.Text; namespace _0o {class Person { public string Name; public int Age; public Person(string name, int age) { this.Name = name; this.Age = age; } public void ShowName() { Console.WriteLine("姓名为:{0}", Name); } public void ShowAge() { Console.WriteLine("年龄为:{0}", Age); } public void Judge() { if (Age >= 10 && Age <= 17) { Console.WriteLine("少年"); } else if (Age <= 34) { Console.WriteLine("青年"); } else if (Age <= 59) { Console.WriteLine("中年"); } else if (Age >= 60) { Console.WriteLine("老年"); } } } class Program { static void Main(string[] args) { Person p = new Person("张红", 32); p.ShowName(); p.ShowAge(); p.Judge(); Console.ReadLine(); } } } 工资类,输出工资 using System; using System.Collections.Generic; using System.Text; namespace _11 { class Program { public class Employee { private string _Name; public string Name { get { return _Name; } set { _Name = value; } } private int _Age; public int Age { get { return _Age; } set { _Age = value; } } private string _Sex; public string Sex { get { return _Sex; } set { _Sex = value; } } private double _Salary; public double Salary { get { return _Salary; } set { _Salary = value; } } public void Addsalary(double salary) { if (salary < 800) salary = 800; else salary = salary + salary * 0.1; Console.WriteLine("增加的薪水为:{0}", salary); } public void ShowSalary(double salary) { Console.WriteLine("职员薪水:{0}", salary); } } static void Main(string[] args) { { Employee s1 = new Employee(); s1.Name = "zhanghua"; s1.Age = 32; s1.Sex = "男"; s1.Addsalary(1200); s1.ShowSalary(1600); Console.ReadKey(); } } } } 学生类 姓名性别出生日期 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication3 { public class Student { private string _Name; public string Name { get { return _Name;} set { _Name = value;} } private string _Sex; public string Sex { get { return _Sex; } set { _Sex = value; } } public DateTime _Birth; public Student(string name,string sex,DateTime birth) { this ._Name=name; this ._Birth=birth; this ._Sex=sex; } public void Study(string courseName) { Console .WriteLine("我正在学习课程的名称:{0}",courseName); } public void Sing(string musicName) { Console .WriteLine("我正在演唱的歌曲:{0}",musicName); } } class Program { static void Main(string[] args) { Student stu_new = new Student("张艺璇","女",Convert.ToDateTime("1993-06-06")); Console.WriteLine("Stu_new对象的学生姓名为:{0},性别为:{1},出生日期为:{2}。",stu_new.Name,stu_new.Sex,stu_new._Birth); stu_new.Study("C#程序设计"); stu_new.Sing("成长。 "); Console.ReadLine(); } } } 学号姓名年龄 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { public class Student { private string _Id; public string Id { get { return _Id; } set { _Id = value; } } private string _Name; public string Name { get { return _Name; } set { _Name = value; } } private string _Sex; public string Sex { get { return _Sex; } set { if (value == "男" || value == "女") _Sex = value; else Console.WriteLine("你输入的性别不符合要求"); } } private int _Age; public int Age { get { return _Age; } set { if (value >= 15 && value <= 20) _Age = value; else Console.WriteLine("你输入的年龄不符合要求"); } } public Student(string id, string name, string sex, int age) { this._Id = id; this._Name = name; this._Sex = sex; this._Age = age; } } class Program { static void Main(string[] args) { Student Stu_new = new Student("201015060014", "张三", "男", 19); Console.WriteLine("学生学号为:{0},姓名为:{1},性别为:{2},年龄为:{3}", Stu_new.Id, Stu_new.Name, Stu_new.Sex, Stu_new.Age); Console.ReadLine(); } } } 异常处理 using System; using System.Collections.Generic; using System.Text; namespace t2 { class Program static void Main(string[] args) { try {int a, b; string op; Console.WriteLine("请输入a的值:"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入b的值:"); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入操作符号:"); op=Console.ReadLine(); switch (op) { case"+": Console.WriteLine("a+b={0}", a + b); break; case"-": Console.WriteLine("a-b={0}", a - b); break; case"*": Console.WriteLine("a*b={0}", a * b); break; case"/": Console.WriteLine("a/b={0}", a / b); break; default: Console.WriteLine("抱歉您输入的操作符有误~"); break; } Console.ReadLine(); } catch (ArithmeticException ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } } }
本文档为【输入两个数相加相减相乘相除并显示结果】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_353097
暂无简介~
格式:doc
大小:31KB
软件:Word
页数:14
分类:互联网
上传时间:2017-11-17
浏览量:169