} }
(5) 分析程序,写出程序的运行结果,并上机进行验证。
using System; namespace _1 {
class Program {
enum WeekDay { sun,mon,tue,wed,thu,fri,sat} static void Main() {
WeekDay a = WeekDay.sun; Console.WriteLine(a); WeekDay b = (WeekDay)4; Console.WriteLine(b); Console.Read(); } }
}
(6) 分析程序,写出程序的运行结果,并上机进行验证。
using System; namespace _1 {
class Program {
static void Main(string[] args) {
int[][] jagArray=new int[2][]{new int[5],new int[3]}; for (int i = 0; i < jagArray.GetLength(0); i++) {
for (int j = 0; j < jagArray[i].Length; j++) jagArray[i][j] = i + j; }
for (int k = 0; k < 2;k++) {
Console.WriteLine(\ for(int m=0;m Console.Read(); } } } (7) 分析程序,写出程序的运行结果,并上机进行验证。 using System; namespace _1 { class Program { static void Main(string[] args) { object x; x = 1; Console.WriteLine(\ x = 10.01; Console.WriteLine(\ x = '\a'; Console.WriteLine(\ x = \ Console.WriteLine(\ Console.Read(); } } } (8) 分析程序,写出程序的运行结果,并上机进行验证。 using System; namespace _1 { class Program { static void Main(string[] args) { Console.Write(\请输入1-12之间的任意一个整数:\ string s=Console.ReadLine(); int month =int .Parse(s); switch(month) { case 1:Console.WriteLine(\ case 2:Console.WriteLine(\ case 3:Console.WriteLine(\ case 4:Console.WriteLine(\ case 5:Console.WriteLine(\ case 6:Console.WriteLine(\ case 7:Console.WriteLine(\ case 8:Console.WriteLine(\ case 9:Console.WriteLine(\ case 10:Console.WriteLine(\ case 11:Console.WriteLine(\ case 12:Console.WriteLine(\ default:Console.WriteLine(\输入错误,转换失败。\ } Console.Read(); } } } (9)分析程序,写出程序的运行结果,并上机进行验证。 using System; namespace _1 { class Program { static void Main(string[] args) { int[,] a = new int[5, 5]; a[0, 0] = 1; for (int i = 1; i < 5; i++) { a[i, 0] = 1; a[i, i] = 1; for (int j = 1; j < i; j++) a[i, j] = a[i - 1, j - 1] + a[i - 1, j]; } for (int i = 0; i < 5; i++) { for (int j = 0; j <= i;j++ ) Console.WriteLine(\ Console.WriteLine(); } Console.Read(); } } } (10)分析程序,写出程序的运行结果,并上机进行验证。 using System; namespace _1 { class Program { static void Main(string[] args) { int odd = 0, even = 0; int[] array = new int[] { 0, 4, 7, 8, 9, 10, 14, 17, 19, 24, 56 }; foreach (int i in array) { if (i % 2 == 0) even++; else odd++; } Console.WriteLine(\个奇数,{1}个偶数\ } } } (11)分析程序,写出程序的运行结果,并上机进行验证。 using System; public class TestDoWhile { public static void Main () { int x; int y = 0; do { x = y++; Console.WriteLine(x); } while(y < 5); } } (12)分析程序,写出程序的运行结果,并上机进行验证。 using System; namespace _1 { class Program { static void Main(string[] args) { Console.WriteLine(\ for (int i = 0; i < 10; i++) { if (i == 5) break; Console.WriteLine(\ } Console.WriteLine(\ for (int i = 0; i < 10; i++)