ImageVerifierCode 换一换
格式:DOCX , 页数:27 ,大小:166.27KB ,
资源ID:18954907      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/18954907.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C#程序设计实验报告2要点Word格式.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C#程序设计实验报告2要点Word格式.docx

1、using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_1 class Program static void Main(string args) const double PI = 3.14159; double r, perimeter, area, volume; Console.Write (请输入半径:); String s = Console.ReadLine(); r = double.Parse(s); Console.WriteLine(圆的半径为=0,r); peri

2、meter = 2 * PI * r; area = PI * r * r; volume = 4 / 3 * PI * Math.Pow(r, 3);圆的周长为=0,面积为=1,perimeter ,area );球体的体积=0,volume ); Console.ReadLine(); 2-2求三角形的周长和面积namespace _2_2 double a, b, c, p, h, area; Console.Write(请输入三角形的边a: string s = Console.ReadLine(); a = double.Parse(s); Console .Write (请输入三角

3、形的边b: s = Console.ReadLine(); b = double.Parse(s); 请输入三角形的边c: c = double.Parse(s); if (a 0 & b c a + b c & a + c b & b + c a)三角形三边分别为:a=0,b=1,c=2,a,b,c); p = a + b + c; h = p / 2; area = Math.Sqrt(h * (h - a) * (h - b) * (h - c);三角形的周长=0,面积为=1,p,area); else Console.WriteLine(无法构成三角形! Console.ReadKey

4、();2-3分段函数的实现运行结果namespace _2_3_2 double x, y;请输入x: x = double.Parse(s); y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x); if(x=0) y=Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math.E,4)-Math .Pow (x+1,3);方法二: else y=Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math .E,4)

5、-Math .Pow (x+1,3);方法三: y=(x=0)?(x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x):Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math .E,4)-Math .Pow (x+1,3);方法四: Console .ReadKey ();2-4三个数比较大小namespace _2_4 int a, b, c, a1, b1, c1, t, Nmax, Nmin, Nmid; Random rMun = new Random(); a = rMu

6、n.Next(101); b = rMun.Next(101); c= rMun.Next(101);原始值: a1 = a; b1 = b; c1 = c; b) t = a; a = b; b = t; c) a = c; c = t; if (b t = b; b = c; Console.WriteLine(方法一)升序值:),a,b,c); a = a1; b = b1; c = c1; Nmax =Math .Max (Math .Max (a,b),c); Nmin = Math.Min(Math.Min(a, b), c); Nmid = a + b + c - Nmax -

7、Nmin; a = Nmin; b = Nmid; c = Nmax;(方法二)升序值:2-5求解一元二次方程namespace Console2_5 double a, b, c, delta, x1, x2, realPart, imagePart;请输入系数a:请输入系数b:请输入系数c: if(a=0) if(b=0) Console.WriteLine(此方程无解!此方程的解为:0,-c/b); else delta=b*b-4*a*c; if(delta x1=(-b+Math.Sqrt(delta)/(2*a); x2=(-b-Math.Sqrt(delta)/(2*a);此方程

8、有两个不等实根:0,1,x1,x2); if(delta =0)Console.WriteLine(此方程有两个相等实根:,-b/(2*a); realPart=-b/(2*a); imagePart=Math.Sqrt(-delta)/(2*a);0+1i和0-1i,realPart,imagePart);2-6switch语句实现多重分支namespace ConsoleApplication1 int i;输入一个数字(17): i = int.Parse(s); switch(i) case 1:对应的星期为:星期一 break; case 2:星期二 case 3:星期三 case

9、4:星期四 case 5:星期五 case 6:星期六 case 7:星期日 default:输入错误! break ;2-7分别使用if语句和switch语句实现多分支结构运行结果(if语句)namespace Console2_7 int c; double f = 0;请输入有固定工资收入的党员的月工资: int salary = int.Parse(Console.ReadLine(); if (salary 1500) c = 15; else c = (salary - 1) / 100; switch (c) case 0: f = 0.5 / 100 * salary; f =

10、 1.5 / 100 * salary; case 8: case 9: case 10: case 11: case 12: case 13: case 14: f = 2.0 / 100 * salary; case 15: f = 3.0 / 100 * salary;月工资=0,交纳党费=1, salary, f);法二代码:(if语句)namespace _2_7_2请输入有固定收入的党员的月工资: salary 400 &= 600) f = 1.0 / 100 * salary; 600 &= 800) f = 1.5 / 100 * salary; 800 &= 1500) f

11、 = 2.0 / 100 * salary; 1500) f = 3.0 / 100 * salary;月工资输入有误!月工资=0,交纳党费=1实验三:3-1namespace _3_1 int i, n, fac = 1; string s; n = -1; while (n 0)请输入非负整数n: n = int.Parse(s); /方法一:for循环 for (i = 1; i = n; i+) fac *= i; For循环:0!=1, n, fac); /方法二:while语句循环 i = 1; fac = 1; while (i = n) fac *= i+; while循环:

12、/方法三:do.while语句循环 do fac *= i; i+; while (i = n); do.while循环:3-2namespace _3_2 int f1 = 1, f2 = 1, f3, num = 2;0,5t0,5t, f1, f2); f3 = f1 + f2; while (f3 = 10000)0,5t, f3); num+; if (num % 5 = 0) Console.WriteLine(); f1 = f2; f2 = f3;3-3、鸡兔同笼问题namespace _3_3 int c, r;请输入总头数: int h = int.Parse(s); in

13、t f = 1; while (f % 2 != 0)请输入总脚数(必须是偶数): f = int.Parse(s);利用循环 bool solution = false; for (c = 0; c =0&c方法二:,c ,r); solution =true ;solution) Console.WriteLine(3-4利用级数和求PI运行结果:namespace Consolejishuhe3_4 float n, t,pi; int s; pi = 0; t = 1; n = 1; s = 1; while (Math.Abs(t) = Math.Pow(10, -6) pi += t; n += 2; s = -s; t = s / n; pi *= 4;pi=0, pi);3-5namespace ConsoleG_3_6

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1