zoukankan      html  css  js  c++  java
  • 函数

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace 函数练习
    {
        class Program
        {
            /// <summary>
            /// 输入一个数,求和函数
            /// </summary>
            /// <param name="n"></param>
            /// <returns></returns>
            public int qiuhe(int n)
            {
                int sum = 0;
                for (int i = 0; i <=n; i++)
                {
                    sum += i;
                }
                return sum;
            }
            /// <summary>
            /// 几千几百减几百不退位,无返回值,无参数
            /// </summary>
            public void butuiwei()
            {
                Random r = new Random();
                int c, d, e, f;
                int a = r.Next(1, 10);
                int b = r.Next(1, 10);
                f = r.Next(1, b);
                d = a * 1000 + b * 100;
                e = f * 100;
                if (b >= f)
                {
                    c = d - e;
                    Console.WriteLine(d + "-" + e + "=" + c);
                }
                else
                {
                    Console.WriteLine("错误");
                }
            }
            /// <summary>
            /// 判断闰年,返回结果
            /// </summary>
            /// <param name="s"></param>
            /// <returns></returns>
            public string runnian(string s)
            {
                string s1 = "";  
                string s2;
                try
                {
                    DateTime rn1 = Convert.ToDateTime(s + "-2-29");
                    s1 = "年是闰年";
                }
                catch (Exception)
                {
                    s1 = "年不是闰年";
    
                }
                finally
                {
                    s2 = s + s1;
                }
                return s2;
            }
            /// <summary>
            /// 给出单词,打印单词的各个字母
            /// </summary>
            /// <param name="s"></param>
            public void danci(string s)
            {
                int a = s.Length;
                for (int i = 0; i < a; i++)
                {
                    Console.WriteLine(s.Substring(i, 1));
                }
            }
            /// <summary>
            /// 冒泡排序,由大到小
            /// </summary>
            /// <param name="a">int 数组a</param>
            public int[] paixu(int[] a)
            {
                for (int i = 0; i < a.Length; i++)
                {
                    for (int j = i; j < a.Length - 1; j++)
                    {
                        if (a[i] < a[j + 1])
                        {
                            int b;
                            b = a[i];
                            a[i] = a[j + 1];
                            a[j + 1] = b;
                        }
                    }
                }
                return a;
            }
            /// <summary>
            /// 数组求和
            /// </summary>
            /// <param name="a"></param>
            /// <returns></returns>
            public int shuzuqiuhe(int[] a)
            {
                int x = 0;
                for (int i = 0; i < a.Length; i++)
                {
                    x = a[i] + x;
    
                }
                return x;
            }
            public 
            static void Main(string[] args)
            {
                while (true)
                {
                    double x;
                    int[] a = new int[10];
                    for (int i = 0; i < 10; i++)
                    {
                        Console.WriteLine("" + (i + 1) + "位同学给班长打分:");
                        a[i] = Convert.ToInt32(Console.ReadLine());
                    }
                    new Program().paixu(a);
                    x = new Program().shuzuqiuhe(a);
                    Console.WriteLine("去掉一个最高分" + a[0] + "" + "去掉一个最低分" + a[9] + "");
                    Console.WriteLine("总分是" + x);
                    Console.WriteLine("平均分" + (x / (a.Length - 2)));
                    Console.ReadLine();   
                }
                
            }
        }
    }
  • 相关阅读:
    [leetcode-102-Binary Tree Level Order Traversal]
    c# 常规验证基类
    不错的silverlight教程
    js 遮罩层请稍后
    登陆冻结账户思路
    mvc json 日期问题的最简单解决方法
    EF 常见语句以及sql语句简单 后续继续添加
    Entity Framework edmx(mapping文件)
    asp.net服务器推送长连接
    数据字典根据组别再分类
  • 原文地址:https://www.cnblogs.com/happinesshappy/p/4520760.html
Copyright © 2011-2022 走看看