cs104 数组枚举.docVIP

  • 2
  • 0
  • 约1.42万字
  • 约 17页
  • 2016-12-18 发布于湖北
  • 举报
104 说明:做完一个题目后,请将源程序和运行结果截图直接复制到题目的下面。运行结果截图请调节到合适的大小。源程序必须是文本,不能是截图。(界面截图的复制:Alt+PrtSc,粘帖:Ctrl+v) 创建一个控制台项目,项目名称为“姓名_104”。项目存放在F盘之下。 Part 1 一维数组 编程:把下面的数组中的正的偶数输出,并输出这些数的和以及数量。 108, 101, 3, -9, -8, 10, -19, 10, 12, 8, -18, -4, 14, 11,28,46,-25,107, 82,74,95,113,-77,69,-28,37,36, 100,-92,88,102,68,-63,20,33,81 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[] x = { 108, 101, 3, -9, -8, 10, -19, 10, 12, 8, -18, -4, 14, 11, 28, 46, -25, 107, 82, 74, 95, 113, -77, 69, -28, 37, 36, 100, -92, 88, 102, 68, -63, 20, 33, 81 }; int sum = 0, count = 0; Console.WriteLine(该数组中的正的偶数:); for (int i = 0; i x.Length; i++) { if (x[i] % 2 == 0 x[i] 0) { Console.WriteLine(x[i]); count++; sum = sum + x[i]; } } Console.WriteLine(和是: + sum); Console.WriteLine(数量是: + count); Console.ReadLine(); } } } 已知如下的变量: int a=10,b=25,c=40,d=80,e=30,f=13; 将上面这些变量构建一个数组,然后用循环输出数组的元素。 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 a = 10, b = 25, c = 40, d = 80, e = 30, f = 13; int[] x = { a, b, c, d, e, f }; for (int i = 0; i x.Length; i++) { Console.WriteLine(x[i]); } Console.ReadLine(); } } } 已知如下的变量: DateTime d1=DateTime.Now, d2=DateTime.Now.AddMonths(1), d3=new DateTime(2013,4,8); DateTime d4=new DateTime(2014,11,10), d5=DateTime.Now.AddDays(200); 将上面这些变量构建一个数组,然后用循环输出数组中每个日期是星期几。 using System; using System.Collections.Generi

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档