初识c#
2021-03-10 04:30
标签:index triangle mono lmin close case console rgs mes 初识c# 标签:index triangle mono lmin close case console rgs mes 原文地址:https://www.cnblogs.com/unknowcry/p/11863013.html 1 //输入三角形或者长方形边长,计算其周长和面积并输出
2 using System;
3
4 namespace tur1_1
5 {
6 class Program
7 {
8 static double calTriangleArea(double a,double b,double c)
9 {
10 double p = (a + b + c) / 2;
11 double res = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
12 return res;
13 }
14
15 static double calTrianglePerimeter(double a,double b,double c)
16 {
17 double res = a + b + c;
18 return res;
19 }
20
21 static double calRectangleArea(double a,double b)
22 {
23 double res = a * b;
24 return res;
25 }
26
27 static double calRectanglePerimeter(double a,double b)
28 {
29 double res = (a + b) * 2;
30 return res;
31 }
32 static void Main(string[] args)
33 {
34 bool flag = true;
35 do
36 {
37 Console.WriteLine("input rectangle or triangle side length,2 or 3 params split with ‘ ‘ as :2 3 ");
38 string str = Console.ReadLine();
39 string[] nums = str.Split(new string[] { " " }, StringSplitOptions.None);
40 double[] num = new double[3];
41 int i = 0;
42 foreach (string n in nums)
43 {
44 num[i] = Convert.ToDouble(n);
45 i++;
46 }
47 switch (i)
48 {
49 case 2:
50 double rc = calRectanglePerimeter(num[0], num[1]);
51 Console.WriteLine("Rectangle perimeter is " + rc);
52 double rs = calRectangleArea(num[0], num[1]);
53 Console.WriteLine("Rectangle area is " + rs);
54 break;
55 case 3:
56 double tc = calTrianglePerimeter(num[0], num[1], num[2]);
57 Console.WriteLine("Triangle primeter is " + tc);
58 double ts = calTriangleArea(num[0], num[1], num[2]);
59 Console.WriteLine("Triangle area is " + ts);
60 break;
61 default:
62 Console.WriteLine("input error");
63 break;
64 }
65 Console.WriteLine("continue(0),exit(1)");
66 string ck = Console.ReadLine();
67 int k = Convert.ToInt32(ck);
68 if(k!=0)
69 {
70 flag = false;
71 }
72 } while (flag);
73 }
74 }
75 }
1 //根据输入的月份判断所在季节
2 using System;
3
4 namespace tur1_2
5 {
6 class Program
7 {
8 static void Main(string[] args)
9 {
10 bool flag = true;
11 do
12 {
13 Console.WriteLine("input month number");
14 string str = Console.ReadLine();
15 int month = Convert.ToInt32(str);
16 switch (month)
17 {
18 case 3:
19 case 4:
20 case 5:
21 Console.WriteLine("春季");
22 break;
23 case 6:
24 case 7:
25 case 8:
26 Console.WriteLine("夏季");
27 break;
28 case 9:
29 case 10:
30 case 11:
31 Console.WriteLine("秋季");
32 break;
33 case 12:
34 case 1:
35 case 2:
36 Console.WriteLine("冬季");
37 break;
38
39 default:
40 Console.WriteLine("input error");
41 break;
42 }
43 Console.WriteLine("continue(0),exit(1)");
44 string ck = Console.ReadLine();
45 int k = Convert.ToInt32(ck);
46 if (k != 0)
47 {
48 flag = false;
49 }
50 } while (flag);
51 }
52 }
53 }
1 /*
2 用 while 循环语句实现下列功能:有一篮鸡蛋,不止一个,有人两个两
3 个数,多余一个,三个三个数,多余一个,再四个四个地数,也多余一个,请问这篮鸡蛋至
4 少有多少个
5 */
6 using System;
7
8 namespace tur1_3
9 {
10 class Program
11 {
12 static void Main(string[] args)
13 {
14 int i = 2;
15 while(i%2!=1||i%3!=1||i%4!=1)
16 {
17 i++;
18 }
19 Console.WriteLine(i);
20 }
21 }
22 }
1 //计算数组中奇数之和和偶数之和
2 using System;
3
4 namespace tur1_4
5 {
6 class Program
7 {
8 static void Main(string[] args)
9 {
10 bool flag = true;
11 do
12 {
13 Console.WriteLine("input number array length");
14 string str = Console.ReadLine();
15 int length = Convert.ToInt32(str);
16 int[] nums = new int[length];
17 long even = 0;
18 long odd = 0;
19 for(int i=0;i
1 //找一个二维数组中的鞍点
2 using System;
3
4 namespace tur1_5
5 {
6 class Program
7 {
8 static void Main(string[] args)
9 {
10 bool flag = true;
11 do
12 {
13 Console.WriteLine("input number array row length");
14 string srow = Console.ReadLine();
15 int row = Convert.ToInt32(srow);
16 Console.WriteLine("input number array col length");
17 string scol = Console.ReadLine();
18 int col = Convert.ToInt32(scol);
19 if(row1||col1)
20 {
21 continue;
22 }
23 int[,] nums = new int[row,col];
24 for (int i = 0; i )
25 {
26 for(int j=0;j
上一篇:Windows - 常见疑问
下一篇:【java日期格式化】