C#实验三数组

上传人:cl****1 文档编号:485422152 上传时间:2022-12-13 格式:DOC 页数:11 大小:132.50KB
返回 下载 相关 举报
C#实验三数组_第1页
第1页 / 共11页
C#实验三数组_第2页
第2页 / 共11页
C#实验三数组_第3页
第3页 / 共11页
C#实验三数组_第4页
第4页 / 共11页
C#实验三数组_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《C#实验三数组》由会员分享,可在线阅读,更多相关《C#实验三数组(11页珍藏版)》请在金锄头文库上搜索。

1、实验 4 数组一、实验学时:2课时二、实验目标1了解数组的概念,掌握数组的声明、初始化方式;2熟练掌握foreach语句的用法;3了解多维数组的定义和声明,理解规则数组和不规则数组的使用区别;4掌握数组转换和数组排序方法的使用; 5掌握array类静态方法运用;三、实验要求1在上实验课之前,每一个同学必须将实验的题目、程序编写完毕,做好充分的准备。2所有实验环节均由每位同学独立完成,严禁抄袭他人实验结果,若发现有结果雷同者,按实验课考核办法处理。3写出程序,并调试程序,要给出测试数据和实验结果。4. 整理上机步骤,总结经验和体会。5实验环境要求:Visual Stuudio 2010。6实验知

2、识点要求:数组。四、实验内容本实验共有三个实验任务。I、实验任务1:数组的声明和使用。在本实验任务中,将声明并使用数组。声明一个数组,将一年中的12个月的英文存入其中。当用户输入月份的数字时,打印出月份的英文。若输入0则退出,并提供输入信息不合法提示,如下:请输入月份数,若输入0则退出:(输入2,显示February)2Februaryusing System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ShuZu class Program static void Main(st

3、ring args) string Month = January, February, March, April, May, June, July, August, September, October, November, December ; string mon; int month; Console.WriteLine(请?输?入?月?份Y数y,?若?输?入?0则退?出?); mon = Console.ReadLine(); month =Convert.ToInt16(mon); if (month = 0) Console.WriteLine(程序即将?退?出?!?); els

4、e Console.WriteLine(0, Monthmonth - 1); System.Console.WriteLine(); II、实验任务2:数组和数组类静态方法结合应用。产生10个1到50之间的随机整数放在数组中,然后对这个数组的进行排序(降序) ,利用已做好程序(昨天布置课堂作业),利用Array类Sort()和Reverse()来进行完成这道程序。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1 clas

5、s shuzhu static void Main(string args) int max; int min; int shuzu = new int10; Console.WriteLine(随?机产生50以?内的?10个?随?机数y); Random random = new Random(); for (int i = 0; i 10; i+) shuzu i = random.Next(1, 50); Console.WriteLine(第0个?数y是?:o1 ,i+1,shuzui ); Console.WriteLine(Sort排?序结果?:o ); Console.Write

6、Line(); Array.Sort(shuzu); for (int i = 0; i 10; i+) / shuzui = random.Next(1, 50); Console.WriteLine(第0个?数y是?:o1, i + 1, shuzui); max = min = shuzu0; for (int i = 0; i max) max = shuzui; else if(i min) min = shuzui; Console.WriteLine(最?大值是?0,最?小?值是?1, max, min); Console.ReadLine(); using System;usi

7、ng System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1 class shuzhu static void Main(string args) int max; int min; int shuzu = new int10; Console.WriteLine(随?机产生50以?内的?10个?随?机数y); Random random = new Random(); for (int i = 0; i 10; i+) shuzu i = random.Next(

8、1, 50); Console.WriteLine(第0个?数y是?:o1 ,i+1,shuzui ); Console.WriteLine(Sort排?序结果?:o ); Console.WriteLine(); Array.Reverse(shuzu); / Array.Reverse(shuzhu); for (int i = 0; i 10; i+) / shuzui = random.Next(1, 50); Console.WriteLine(第0个?数y是?:o1, i + 1, shuzui); max = min = shuzu0; for (int i = 0; i max

9、) max = shuzui; else if(i min) min = shuzui; Console.WriteLine(最?大值是?0,最?小?值是?1, max, min); Console.ReadLine(); III、实验任务3:交错数组应用。利用交错数组编写程序实现下列图形。模仿书上例子4-612 43 9 27 4 16 64 2565 25 125 625 3125using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace JiaoCuoShuZu class Program static void Main(string args) const int k = 5; int arr = new intk; for (int i = 0; i arr.Length; i+) for (int j = 1; j arr.Length+1; j+) arri = new intj; for (int i = 0; i arr.Length; i+) for (int j = 0; j arri.Length; j+) if (i = 0 & j = 0

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号