zoukankan      html  css  js  c++  java
  • 函数

    把经常用的程序写成函数,直接调用,可以减少编写程序的工作量。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            public static bool zhishu(int shu)
            {
                int c = 0;
                for (int i = 1; i <= shu; i++)
                {
                    if (shu % i == 0)
                    {
                        c++;
                    }
    
                }
                if (c == 2)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public void bzz(string s, int t, int g)
            {
                if (s == "")
                {
                    double n = t - g + 100;
                    if (n >= -3 && n <= 3)
                    {
                        Console.WriteLine("标准");
                    }
                    else if (n > 3)
                    {
                        Console.WriteLine("偏胖");
                    }
                    else
                    {
                        Console.WriteLine("偏瘦");
                    }
                }
                else if (s == "")
                {
                    double n = t - g + 110;
                    if (n >= -3 && n <= 3)
                    {
                        Console.WriteLine("标准");
                    }
                    else if (n > 3)
                    {
                        Console.WriteLine("偏胖");
                    }
                    else
                    {
                        Console.WriteLine("偏瘦");
                    }
                }
                else
                {
                    Console.WriteLine("输入有误");
                }
            }
            
    
                           
            static void Main(string[] args)
            {
                Console.WriteLine("请输入一个数");
                int b = int.Parse(Console.ReadLine());
                bool a = Program.zhishu(b);
                if (a) 
                {
                    Console.WriteLine("是质数");
                }
                else {
                    Console.WriteLine("不是质数");
                }
                Console.WriteLine("请输入性别");
                string c = Console.ReadLine();
                Console.WriteLine("请输入体重");
                int d = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入身高");
                int e = int.Parse(Console.ReadLine());
                Program p = new Program();
                p.bzz(c, d, e);
                
                Console.ReadLine();
            }
        }
    }

    质数  身高体重标准

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication7
    {
        class Program
        {
            public static int[] paixu (int []arr)//定义数组,冒泡排序
            {
                for (int i = 0; i <= arr.Length; i++)
                {
                    for (int j = i; j <= arr.Length - 1; j++)
                    {
                        if (arr[i] < arr[j])
                        {
                            int zhong = 0;
                            zhong = arr[i];
                            arr[i] = arr[j];
                            arr[j] = zhong;
                        }
                    }
    
                }
                for (int i = 0; i < arr.Length; i++)
                {
                    Console.Write(arr[i]+" ");
                }
                return arr;//排好之后输出
            }
            static void Main(string[] args)
            {
                Console.WriteLine("请输入人数");//输入人数
                int renshu = int.Parse(Console.ReadLine());
                int[] arr = new int[renshu];
    
                for (int h = 1; h <= renshu; h++)
                {
                    Console.WriteLine("请输入第{0}个人的成绩", h);//输入成绩
                    arr[h - 1] = int.Parse(Console.ReadLine());
                   
                }
    
    
                 Program.paixu(arr);//调用函数,输出
                
                
                Console.ReadLine();
            }
        }
    }

    冒泡排序

  • 相关阅读:
    编写EasyCluster V2.0 Portal主界面时的HTML心得(NOWRAP)
    Learning Perl 4ed Reading Notes Chapter4 Subroutines
    Ajax的异步,是鸡肋还是鸡排?
    JavaScript中使用eval函数将一个String当成一句JS代码来执行
    AJAX中消除Tomcat会cache action返回值的问题
    Learning Perl 4ed Reading Notes Chapter2 Scalar Data
    你知道这个语法吗?
    33中JS效果整理
    SQL语法大全[转]
    JS表单判断函数代码大全
  • 原文地址:https://www.cnblogs.com/jskbk/p/5359389.html
Copyright © 2011-2022 走看看