码迷,mamicode.com
首页 > 其他好文 > 详细

函数的应用

时间:2014-12-29 22:48:37      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

10个评委打分,去掉两个最高分和两个最低分,求平均分

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace ConsoleApplication1
 7 {
 8     class Class1
 9     {
10         static void Main(string[] args)
11         {
12             int[] a = new int[10];
13             //亮分
14             ShuRu(a);
15 
16             //排序
17             PaiXu(a);
18 
19             //运算求平均
20             double avg = YunSuan(a);
21 
22             //输出显示
23             ShuChu(a, avg);
24         }
25 
26         private static void ShuChu(int[] a, double avg)
27         {
28             Console.WriteLine("去掉两个最高分:" + a[0] + "" + a[1]);
29             Console.WriteLine("去掉两个最低分:" + a[a.Length - 1] + "" + a[a.Length - 2]);
30             Console.WriteLine("该选手最终得分为:" + avg);
31         }
32 
33         private static double YunSuan(int[] a)
34         {
35             //求总分
36             int sum = 0;
37             for (int i = 2; i <= a.Length - 3; i++)
38             {
39                 sum += a[i];
40             }
41             //求平均
42             double avg = (1.0 * sum) / (a.Length - 4);
43             return avg;
44         }
45 
46         private static void PaiXu(int[] a)
47         {
48             for (int i = 1; i <= a.Length - 1; i++)
49             {
50                 for (int j = 1; j <= a.Length - i; j++)
51                 {
52                     if (a[j] > a[j - 1])
53                     {
54                         int temp = a[j];
55                         a[j] = a[j - 1];
56                         a[j - 1] = temp;
57                     }
58                 }
59             }
60         }
61 
62         private static void ShuRu(int[] a)
63         {
64             for (int i = 0; i < a.Length; i++)
65             {
66                 Console.Write("请第" + (i + 1) + "号评委亮分:");
67                 a[i] = Convert.ToInt32(Console.ReadLine());
68             }
69         }
70     }
71 }

 

天气预报

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace ConsoleApplication1
 7 {
 8     class Program
 9     {
10         static void M1ain(string[] args)
11         {
12             ShowHeader();
13 
14             string city = ShuRu();
15 
16             string jieguo = YunSuan(city);
17 
18             Console.WriteLine("天气预报仅做参考:" + jieguo);
19 
20         }
21 
22         private static string YunSuan(string city)
23         {
24             //天气
25             string[] s = new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "多云", "小雨", "中雨", "大雨", "暴雨", "雷阵雨", "小雪", "中雪", "大雪", "", "" };
26             Random rand = new Random();
27             int n = rand.Next(s.Length); //天气的下标.
28             string tq = s[n];
29 
30             //气温
31             int c = rand.Next(70);
32             c -= 30;
33 
34             string jieguo = "明天的天气情况:" + city + ",天气:" + tq + ",气温:" + c;
35             return jieguo;
36         }
37 
38         private static string ShuRu()
39         {
40             Console.Write("城市:");
41             string city = Console.ReadLine();
42             return city;
43         }
44 
45         private static void ShowHeader()
46         {
47             Console.WriteLine("*************天气预报****************");
48             Console.WriteLine("********淄博气象台权威发布****************");
49             Console.WriteLine("********如果出现异常 ,纯属偶然****************");
50             Console.WriteLine("*****仅做个人测试与爱好使用,不要用作商业运营**********");
51         }
52         
53     }
54 }

 

函数的应用

标签:

原文地址:http://www.cnblogs.com/viven/p/4192417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!