今天进行了Visual Stido.NET 实验环境配置。完成了第一个实验。

题目一: 编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出。

 

 

 1 // See https://aka.ms/new-console-template for more information
 2 using System;
 3 
 4 namespace sy1
 5 
 6 {
 7 
 8     class Program
 9 
10     {
11 
12         static void Main(string[] args)
13 
14         {
15 
16             string a;
17 
18             Console.WriteLine("请输入a来计算三角形,或者b来计算矩形");
19 
20             a = Console.ReadLine();
21 
22             if (a == "a")
23 
24             {
25 
26                 sanjiao();
27 
28             }
29 
30             else if (a == "b")
31 
32             {
33 
34                 juxing();
35 
36             }
37 
38             else
39             {
40 
41                 Console.WriteLine("输入错误!");
42 
43 
44 
45             }
46 
47             void sanjiao()
48             {
49 
50                 Console.WriteLine("请输入三角形第一个边长num1:");
51 
52                 double num1 = double.Parse(Console.ReadLine());
53 
54                 Console.WriteLine("请输入三角形第二个边长num2:");
55 
56                 double num2 = double.Parse(Console.ReadLine());
57 
58                 Console.WriteLine("请输入三角形第三个边长num3:");
59 
60                 double num3 = double.Parse(Console.ReadLine());
61 
62                 double sumz1 = num1 + num2 + num3;
63 
64                 double s = (num1 + num2 + num3) / 2;
65 
66                 double area = Math.Sqrt(s * (s - num1) * (s - num2) * (s - num3));
67 
68                 Console.WriteLine("三角形的周长为{0},面积为{1}", sumz1, area);
69 
70 
71 
72             }
73 
74             void juxing()
75             {
76 
77                 Console.WriteLine("请输入矩形第一个边长num1:");
78 
79                 double num1 = double.Parse(Console.ReadLine());
80 
81                 Console.WriteLine("请输入矩形第二个边长num2:");
82 
83                 double num2 = double.Parse(Console.ReadLine());
84 
85                 double sumz1 = (num1 + num2) * 2;
86 
87                 double area = num1 * num2;
88 
89                 Console.WriteLine("矩形的周长为{0},面积为{1}", sumz1, area);
90 
91             }
92 
93         }
94 
95     }
96 
97 }
View Code

 题目二:编写一个控制台应用程序,可根据输入的月份判断所在季节。

 

 

 

 

 

 1 using System;
 2 
 3 
 4 
 5 namespace sy1_2
 6 
 7 {
 8 
 9     class Program
10 
11     {
12 
13         static void Main(string[] args)
14 
15         {
16 
17             Console.WriteLine("请输入月份");
18 
19             int a = int.Parse(Console.ReadLine());
20 
21             if (a > 12 || a < 1)
22 
23             {
24 
25                 Console.WriteLine("请输入数字为1-12的月份");
26 
27             }
28 
29             else
30             {
31 
32                 if (a == 1 || a == 3 || a == 2)
33 
34                 {
35 
36                     Console.WriteLine("此时是春季");
37 
38                 }
39 
40                 else if (a == 4 || a == 5 || a == 6)
41 
42                 {
43 
44                     Console.WriteLine("此时是夏季");
45 
46                 }
47 
48                 else if (a == 7 || a == 8 || a == 9)
49 
50                 {
51 
52                     Console.WriteLine("此时是秋季");
53 
54                 }
55 
56                 else if (a == 10 || a == 11 || a == 12)
57 
58                 {
59 
60                     Console.WriteLine("此时是冬季");
61 
62                 }
63 
64                 else
65                 {
66 
67                     Console.WriteLine("输入错误");
68 
69                 }
70 
71 
72 
73             }
74 
75         }
76 
77     }
78 
79 }
View Code

题目三:

编写程序,用 while 循环语句实现下列功能:有一篮鸡蛋,不止一个,有人两个两
个数,多余一个,三个三个数,多余一个,再四个四个地数,也多余一个,请问这篮鸡蛋至
少有多少个。

 

 1 using System;
 2 
 3 
 4 
 5 namespace sy1_3
 6 
 7 {
 8 
 9     class Program
10 
11     {
12 
13         static void Main(string[] args)
14 
15         {
16 
17             int sum = 2;
18 
19             while (sum < 100)
20             {
21 
22                 if (sum % 2 == 1 && sum % 3 == 1 && sum % 4 == 1)
23 
24                 {
25 
26                     Console.WriteLine("这篮鸡蛋至少有{0}个", sum);
27 
28                     break;
29 
30                 }
31 
32                 else
33 
34                     sum++;
35 
36             }
37 
38 
39 
40         }
41 
42     }
43 
44 }
View Code

题目四:编写程序,计算数组中奇数之和和偶数之和。

 

 1 using System;
 2 
 3 
 4 
 5 namespace sy1_4
 6 
 7 {
 8 
 9     class Program
10 
11     {
12 
13         static void Main(string[] args)
14 
15         {
16 
17             int[] a;
18 
19             int b = 0, c = 0;
20 
21             Console.WriteLine("请输入数组的长度:");
22 
23             int length = Convert.ToInt32(Console.ReadLine());
24 
25             a = new int[length];
26 
27             for (int i = 0; i < length; i++)
28 
29             {
30 
31                 Console.Write("请输入第{0}个数组的值:", i);
32 
33                 a[i] = Convert.ToInt32(Console.ReadLine());
34 
35             }
36 
37             for (int j = 0; j < length; j++)
38 
39             {
40 
41                 if (a[j] % 2 == 1)
42 
43                 {
44 
45                     b = b + a[j];
46 
47                 }
48 
49                 else if (a[j] % 2 == 0)
50 
51                 {
52 
53                     c = c + a[j];
54 
55                 }
56 
57             }
58 
59             Console.WriteLine("奇数和为{0},偶数和为{1}", b, c);
60 
61         }
62 
63     }
64 
65 }
View Code

题目五:

编写程序,找一找一个二维数组中的鞍点(即该位置上的元素值在行中最大,在该
列上最小。有可能数组没有鞍点)。要求:
二维数组的大小、数组元素的值在运行时输入;
 程序有友好的提示信息。

 

 

 1 using System;
 2 
 3 
 4 
 5 namespace sy1_5
 6 
 7 {
 8 
 9     class Program
10 
11     {
12 
13         static void Main(string[] args)
14 
15         {
16 
17             Console.WriteLine("输入数组行大小");
18 
19             int b = int.Parse(Console.ReadLine());
20 
21             Console.WriteLine("输入数组列大小");
22 
23             int c = int.Parse(Console.ReadLine());
24 
25             int[,] a = new int[b, c];
26 
27             int max = 0;
28 
29             int[] n = new int[b];
30 
31             for (int i = 0; i < b; i++)
32 
33             {
34 
35                 for (int j = 0; j < c; j++)
36 
37                 {
38 
39                     Console.WriteLine("输入第{0}行第{1}列数", i, j);
40 
41                     int m = int.Parse(Console.ReadLine());
42 
43                     a[i, j] = m;
44 
45                 }
46 
47             }
48 
49             int count = 0;
50 
51             for (int i = 0; i < b; i++)
52 
53             {
54 
55                 max = 0;
56 
57                 for (int j = 0; j < c; j++)
58 
59                     if (a[i, j] > a[i, max])
60 
61                     {
62 
63                         max = j;
64 
65                     }
66 
67                 int minx = 0;
68 
69                 for (int j = 0; j < c; j++)
70 
71                 {
72 
73                     if (a[j, max] < a[minx, max])
74 
75                         minx = j;
76 
77                 }
78 
79                 if (a[i, max] == a[minx, max])
80 
81                 { Console.Write("鞍点[{0},{1}]:{2}" + '\n', minx, max, a[minx, max]); count++; }
82 
83             }
84 
85             if (count == 0) Console.WriteLine("没有鞍点数");
86 
87             else
88 
89             {
90 
91                 Console.WriteLine("鞍点总数为:" + count);
92 
93             }
94 
95         }
96 
97     }
98 
99 }
View Code

目前实验一的所有内容已经完成,心得体会已完成。

posted on 2023-10-08 10:23  夜的第七章i  阅读(11)  评论(0编辑  收藏  举报