已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
程序设计基础C#.NET练习参考答案:一、选择题1.NET的目的就是将_A_作为新一代操作系统的基础,对互联网的设计思想进行扩展。A互联网 B. Windows C. C# D. 网络操作系统2.假设变量x的值为10,要输出x值,下列正确的语句是_C_。ASystem.Console.writeline(“x”) B. System.Cosole.WriteLine(“x”)C. System.Console.WriteLine(“x=0”,x) D. System.Console.WriteLine(“x=x”)3.要退出应用程序的执行,应执行下列的_A_语句。A. Application.Exit(); B. Application.Exit;C. Application.Close(); D. Application.Close;4.关于C#程序的书写,下列不正确的说法是_D_。A 区分大小写B 一行可以写多条语句C 一条语句可以写成多行D 一个类中只能有一个Main()方法,因此多个类中可以有多个Main()方法5. 在C#语言中,下列能够作为变量名的是_C_。Aif B. 3ab C. b_3a D. a-bc7. 能正确表示逻辑关系“a5或a0”的C#语言表达方式是_D_。Aa=5 or a=5|a=5&a=5|ab?(ac?a:c):b);A. 5 B. 4 C. 6 D. 不确定9. If语句后面的表达式应该是_A_。A逻辑表达式 B. 条件表达式 C. 算术表达式 D. 任意表达式10 有如下程序:using System;class Da public static void Main() int x=0,a=0,b=0; Switch(x) case 0;b+;break; case 1:a+;break; case 2;a+;b+;break; Console.WriteLine(“a=0,b=1”,a,b); 该程序的输出结果是_A_。A. a=0,b=1 B. a=1,b=1 C. a=1,b=0 D. a=2,b=211以下叙述正确的是_D_。Adowhile 语句构成的循环不能用其他语句构成的循环来代替Bdowhile语句构成的循环只能用break语句退出C用dowhile语句构成的循环,在while后表达式为true时结束循环D用dowhile语句构成的循环,在while后的表达式应为关系表达式或逻辑表达式12以下关于for循环的说法不正确的是_A_。AFor循环只能用于循环次数已经确定的情况BFor循环是先判定表达式,后执行循环体语句CFor循环中,可以用break语句跳出循环体DFor循环体语句中,可以包含多条语句,但要用花括号括起来13假定int类型变量占用两个字节,若有定义:intx=new int100,1,2,3,4;,则数组x在内存中所占字节数是_A_。A10 B. 20 C. 40 D. 8014以下程序的输出结果是_B_。using System;class temppublic static void Main() int i;inta=new int10; for(i=9;i=0;i-) ai=10-i; Console.WriteLine(012,a3,a6,a9); A. 258 B. 741 C. 852 D. 36915有定义语句:int,a=new int 5,6,则下列正确的数组无素的引用是_D_。A. a(4,5) B. a(4)(5) C. a45 D. a4,516下列的数组定义语句,不正确的是_AB_。A. int a=new int 51,2,3,4,5; B. int ,a=new int a34;C. int a=new int 3; D. int a=1,2,3,4,;四、程序设计题要求:1、 下面所有程序设计题用控制台应用程序编写。2、 每道题目的项目名称为:你的姓名拼音+下划线+题序(例如张三同学第二题的项目名称为:“zhangsan_2” ),程序代码中的类名与项目名称相同。将项目保存到指定的文件夹内。3、 下面每一题运行结果窗口中显示的:第一行格式如下,相对应的“XXX”地方填写每一个学生本人的数据。班级:XXX , 序号:XXX , 姓名:XXX 第二行:空一行第三行开始才是每一题的运行结果内容1、设长方形的长a=1.5,宽b=1.7,求长方形的周长L和面积S。取小数点后二位数字,请编写成控制台应用程序。using System;class cl static void Main() double a = 1.50, b = 1.70, L, S; L = (a + b) * 2; L=Math.Round(L,2) ; S = a * b; S=Math.Round(S,2) ; Console.WriteLine(长方形的周长L:0, L); Console.WriteLine(长方形的面积S:0, S); Console.ReadLine(); 2、 有一函数,当x=1,y=x*x,写一程序输入x,输出y。class Program static void Main(string args) double x, y; Console.Write(请输入数值x:); x = Convert.ToInt16(Console.ReadLine(); if (x 1) y = x; else y = x * x; Console.WriteLine(输出y等于:0,y); 3、有一函数: 1(x0)要求:输入一个x值,输出y值。用控制台应用程序编写。 class Program static void Main(string args) double x, y; Console.Write(请输入数值x:); x = Convert.ToInt16(Console.ReadLine(); if (x 0) y = -1; else y = 0; Console.WriteLine(输出y等于:0,y); 4、 从键盘上任意输入两个整数,并将较大的数显示出来。 class Program static void Main(string args) int x, y,z; Console.Write(请输入数值x:); x = Convert.ToInt16(Console.ReadLine(); Console.Write(请输入数值y:); y = Convert.ToInt16(Console.ReadLine(); if (x y) z=x; else z=y; Console.WriteLine(输出较大的数:0,z); 方法二:using System;class cl static void Main() Console.WriteLine(班级:电子商务2班 , 序号:25号 , 姓名:莫子良n ); int x, y,z; Console.Write(请输入x的值:); x = Convert.ToInt16(Console.ReadLine(); Console.Write(请输入y的值:); y = Convert.ToInt16(Console.ReadLine(); z=Math.Max(x,y); Console.WriteLine(输出较大值:0, z); 5、 从键盘上任意输入三个整数,并将较大的数显示出来。using System;class jdz static void Main() double x, y, z, h,t; Console.Write(请输入数值一x:); x = Convert.ToSingle(Console.ReadLine(); Console.Write(请输入数值二y:); y = Convert.ToSingle(Console.ReadLine(); Console.Write(请输入数值三z:); z = Convert.ToSingle(Console.ReadLine(); if (x y) h = x; else h = y; if (h z) t = h; else t = z; Console.WriteLine(其中最大值为:0,t); Console.ReadLine(); 方法二:using System;class jdz static void Main() double x, y, z, h, t; Console.Write(请输入数值一x:); x = Convert.ToSingle(Console.ReadLine(); Console.Write(请输入数值二y:); y = Convert.ToSingle(Console.ReadLine(); Console.Write(请输入数值三z:); z = Convert.ToSingle(Console.ReadLine(); h = Math.Max(x, y); t = Math.Max(h, z); Console.WriteLine(其中最大值为:0, t); Console.ReadLine(); 6、 输入两个实数,按代数值由小到大的次序输出这两个数。using System;namespace ConsoleApplication2 class Program static void Main(string args) int a, b, c; Console.Write(请输入第一个实数:); a = Convert.ToInt16(Console.ReadLine(); Console.Write(请输入第二个实数:); b = Convert.ToInt16(Console.ReadLine(); if (b a) c = a; a = b; b = c; Console.WriteLine(由小到大排序:0,1, b,a); 方法二:using System;namespace ConsoleApplication2 class Program static void Main(string args) int a, b, c, d; Console.Write(请输入第一个实数:); a = Convert.ToInt16(Console.ReadLine(); Console.Write(请输入第二个实数:); b = Convert.ToInt16(Console.ReadLine(); if (b a) Console.WriteLine(由小到大排序:0,1,a,b); else Console.WriteLine(由小到大排序: 0,1,b,a); 7、 输入三个实数,按代数值由小到大的次序输出这三个数。using System;class jdz static void Main() double a, b, c,t; Console.Write(请输入数值一a:); a = Convert.ToSingle(Console.ReadLine(); Console.Write(请输入数值二b:); b = Convert.ToSingle(Console.ReadLine(); Console.Write(请输入数值三c:); c = Convert.ToSingle(Console.ReadLine(); if(ab) t=a;a=b;b=t; if(ac) t=a;a=c;c=t; if(bc) t=b;b=c;c=t; Console.WriteLine(排序由小到大为:0,1,2,a,b,c); 8、计算n!的程序。using System;namespace ConsoleApplication3 class Program static void Main(string args) int i; long sum = 1,n; Console.Write(请输入数值n:); n = Convert.ToInt64(Console.ReadLine(); for (i = 1; i = n; i+) sum = sum * i; Console.WriteLine(n的阶乘:0, sum); 9、 求100以内的偶数和,即:2+4+6+100的和。using System;namespace ConsoleApplication1 class Program static void Main(string args) int i, sum = 0; for (i = 1; i = 100; i+) if (i % 2 = 1) continue; sum = sum + i; Console.WriteLine(sum=0, sum); 10、编写一个程序,将10 , 20 , 30, 40, 50, 60 这六个数放入一个一维数组中,并输出这六个数中的最大数及最大数的位置及平均值。要求用控制台应用程序编写。using System;namespace ConsoleApplication1 class Program static void Main(string args) int i, ma
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- LY/T 3455-2025竹牙刷
- 护理操作技术护理创新
- 消化系统疾病患者的康复护理
- 手术患者术后心理支持
- 人力资源预算编制流程及模板
- 卫生统计学考试题及答案
- 2026年丛集性头痛诊疗试题及答案(神经内科版)
- 2026年小程序SaaS软件服务合同协议
- 2025年韶山市社区工作者招聘考试真题及答案
- 《食品与药品检测》期末考试复习题库及答案
- 2026年北京市西城区高三二模英语试卷(含答案)
- 济宁市2026届省属公费师范毕业生就业岗位需求备考题库(112个)含答案详解(能力提升)
- 【 道法 】社会主义市场经济体制课件-2025-2026学年统编版道德与法治八年级下册
- 对外投资合作国别(地区)指南-马来西亚(2025年版)
- 心血管植入型电子器械植入术护理专家共识总结2026
- 2025年大学生提干选拔考试历年真题试卷及答案
- 2026年煤矿采煤工试题及答案
- 2025四川宜宾市科技人才集团有限公司第三批员工招聘10人笔试历年参考题库附带答案详解
- 2025年中国邮政经济金融笔试及答案
- 矿用齿轨卡轨车轨道安装要求
- 2025年湖南省政府采购评审专家考试真题库及答案
评论
0/150
提交评论