• 刚学了函数,关于有无参数和返回值的四种情况的查找数字的代码


    static void Main(string[] args)
    {
    ////无参无反
    //cz();

    ////无参有返
    //bool bbb = chaz();
    //if (bbb == true)
    //{
    // Console.WriteLine("找到啦");
    //}
    //else
    //{
    // Console.WriteLine("没找到");
    //}


    ////有参无返
    //Console.WriteLine("请输入一个数");
    //int d = Convert.ToInt32(Console.ReadLine());
    //chazhao(d);


    ////有参有返
    //Console.WriteLine("请输入一个数");
    //int d = Convert.ToInt32(Console.ReadLine());
    //bool b = chazhaoaaa(d);
    //if (b == true)
    //{
    // Console.WriteLine("找到啦");
    //}
    //else
    //{
    // Console.WriteLine("没找到");
    //}

    }
    //有参有返
    static bool chazhaoaaa(int d)
    {

    int[] a = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    bool b = false;
    for (int i = 0; i < a.Length; i++)
    {
    if (a[i] == d)
    {
    b = true;
    break;
    }


    }
    return b;

    }

    //有参无返
    static void chazhao(int d)
    {

    int[] a = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    bool b = false;
    for (int i = 0; i < a.Length; i++)
    {
    if (a[i] == d)
    {
    b = true;
    break;
    }


    }
    if (b == true)
    {
    Console.WriteLine("找到啦");
    }
    else
    {
    Console.WriteLine("没找到");
    }

    }


    //查找 无参有返
    static bool chaz()
    {
    bool b = false;
    Console.WriteLine("请输入一个数");
    int d = Convert.ToInt32(Console.ReadLine());
    int[] a = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };

    for (int i = 0; i < a.Length; i++)
    {
    if (a[i] == d)
    {
    b = true;
    break;
    }


    }

    return b;
    }


    //查找 无参无反
    static void cz()
    {
    Console.WriteLine("请输入一个数");
    int d=Convert.ToInt32(Console.ReadLine());
    int[] a = new int[10] { 1,2,3,4,5,6,7,8,9,0};
    bool b=false;
    for (int i = 0; i < a.Length; i++)
    {
    if (a[i]==d)
    {
    b = true;
    break;
    }


    }
    if (b == true)
    {
    Console.WriteLine("找到啦");
    }
    else
    {
    Console.WriteLine("没找到");
    }

  • 相关阅读:
    web&http协议&django初识
    jQuery
    BOM&DOM
    装饰器
    JavaScript
    模块
    面向对象编程
    函数
    CSS
    HTML
  • 原文地址:https://www.cnblogs.com/zzc134680/p/5429980.html
Copyright © 2020-2023  润新知