




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验报告学院(系)名称:管理学院姓名学号专业信息管理与信息系统班级2班实验项目实验二:结构化程序设计编程课程名称基于.NET的程序设计课程代码实验时间实验地点批改意见:成绩教师签字:1. 实验特点:表达式与条件判断,循环过程。 类型:验证 类别:专业基础 计划学时:4学时 每组人数:1人2. 实验目的及要求:理解并熟练掌握分支结构、循环结构的程序设计方法:在提高程序可读性上下工夫。3. 主要仪器设备: 计算机4. 实验内容提要: 调试8个程序,使用条件、分支、跳转、循环语句编程实现: 5. 内容:(1)正数的四舍五入;源程序代码如下:using System;namespace 四舍五入/ / Class1 的摘要说明。/ class Class1/ / 应用程序的主入口点。/ STAThreadstatic void Main(string args) double x,y; Console.WriteLine(Please input the number:); x=Convert.ToDouble(Console.ReadLine(); if(x0) Console.WriteLine(ERROR!); else y=Math.Round(x); Console.WriteLine(x四舍五入为:0,y); 输入数据及运行结果截图如下:1、 X为正数:2、X为负数(2)任意输入两个数,判断它们的大小并显示判断的结果;源程序代码如下:using System;namespace 判断大小 / / Class1 的摘要说明。/ class Class1 / / 应用程序的主入口点。/ STAThreadstatic void Main(string args)double x,y;Console.WriteLine(Please input the first number(x):);x=Convert.ToDouble(Console.ReadLine();Console.WriteLine(Please input the second number(y):);y=Convert.ToDouble(Console.ReadLine();if(xy) Console.WriteLine(x大于y);else if(x=y)Console.WriteLine(x等于y); else Console.WriteLine(x小于y);输入数据及输出结果截图如下:1、 X大于Y:2、X等于Y3、X小于Y(3)对输入的四个整数,求其中的最大值和最小值;源程序代码如下:using System;namespace 求最大值与最小值/ / Class1 的摘要说明。/ class Class1 / / 应用程序的主入口点。 / STAThreadstatic void Main(string args)double a,max,min;Console.WriteLine(Please input the first number:);max=Convert.ToDouble(Console.ReadLine();min=max;for(int i=1;imax)max=a;else if(a=0时,有两个实根: 当d=b2-4ac= 0) x1 = (-b + Math.Sqrt(d) / (2 * a); x2 = (-b - Math.Sqrt(d) / (2 * a); Console.WriteLine(一元二次方程0X2+1X+2=0的实根为:X1=3, X2=4, a, b, c, x1, x2); else re = -b / (2 * a); im = Math.Sqrt(-d) / (2 * a); Console.WriteLine(一元二次方程0X2+1X+2=0的复根为:X1=3, X2=4, a, b, c, re, im); 运行程序结果截图如下:1、d=0的情况2、 d0的情况:(5) 编写个应用程序,能够从键盘输入一个非负整数,然后计算并输出它的阶乘。源程序代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 求非负整数的阶乘 class Program static void Main(string args) long y = 1; int x,a; Console.WriteLine(Please input x:); x = Convert.ToInt32(Console.ReadLine(); a = x; if (x 0) y *= x; x-; Console.WriteLine(0!=1, a, y); 运行结果截图如下:1、 x为非负整数的情况:2、 x为负数的情况:(6) 编写一个应用程序,通过使用公式:来估计算术常量e 的值。源程序代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 求算数常量e的值 class Program static void Main(string args) double sum = 1; for (int n = 1; ; n+) int temp = 1; for (int i = 1; i = n; i+) temp *= i; if (1 / (Convert.ToDouble(temp) Math. Pow(10, -6) break; sum += 1 / (Convert.ToDouble(temp); Console.WriteLine(e=0, sum); 程序运行结果如下:(7) 写一个应用程序,能通过公式:来计算ex 的值源程序代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 求e_x的值 class Program static void Main(string args) double x,sum = 1; Console.WriteLine(Please input x:); x = Double.Parse(Console.ReadLine(); for (int n = 1; ; n+) int temp = 1; for (int i = 1; i = n; i+) temp *= i; if (Math.Pow(x, n) / (double)temp =60分)与未通过的学生人数及通过率,如果通过大于大于85%,则显示“提高学费”,否则,显示“降低学费”。学习程序编写风格:学习使用注释语句。源程序代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 考试结果总结 class Program static void Main(string args) int i = 1, pass = 0, fail = 0; double gread, sum = 0, prate; while (i 100|gread= 60) pass += 1; else fail += 1; sum += gread; i+; prate = (double)pass / 10; if (prate 0.85) Console.WriteLine(通过考试的人数为:0n未通过考试的人数为:1n通过率为:2n提高学费, pass, fail, prate); else Console.WriteLine(通过考试的人数为:0n未通过考试的人数为:1n通过率为:2n降低学费, pass, fail, prate); 运行结果截图如下:1、 输入数据错误的情况:(1) 输入成绩大于100:(2) 输入成绩小于0:2、 输入数据没错得情况:(1)通过率大
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 8.2.5 生物的变异 说课稿-2025-2026学年鲁科版(五四学制)生物八年级下册
- Chapter1 Study tours教学设计-2025-2026学年小学英语6B香港朗文版
- 第三节 DNA通过复制传递遗传信息教学设计-2025-2026学年高中生物浙科版2019必修2 遗传与进化-浙科版2019
- 十六 项脊轩志教学设计-2025-2026学年高中语文高一下册华东师大版
- 2025年中考数学试题分类汇编:圆的有关位置关系(9大考点51题) (第1期)解析版
- 2025年采购与供应链管理岗位职业技能资格知识考试题与答案
- 1.3地球的历史教学设计2023-2024学年高中地理人教版(2019)必修第一册
- 2025年体育学科专业知识教师招聘考试押题卷及答案(一)
- 一年级语文上册 第7单元 课文3 11 项链说课稿 新人教版
- 蓄水池防溺水知识培训课件
- 物业客服管理知识培训课件
- 2025-2026学年湘教版(2024)初中数学八年级上册教学计划及进度表
- GB/T 45763-2025精细陶瓷陶瓷薄板室温弯曲强度试验方法三点弯曲或四点弯曲法
- 【MOOC】理解马克思-南京大学 中国大学慕课MOOC答案
- 夏商周考古课件 第1章 绪论
- GB/T 23723.1-2009起重机安全使用第1部分:总则
- 《汽车发动机检修》课程标准
- GB308-2002滚动轴承钢球
- 夹芯彩钢复合板吊顶施工方案
- 高二物理培优计划
- 初中英语阅读理解100篇
评论
0/150
提交评论