zoukankan      html  css  js  c++  java
  • 函数,在函数中赋值,然后输出

     public int SumZhiShu(int n)
            {
                int sum = 0;

                for (int i = 1; i <= n; i++)
                {
                    int count = 0;
                    for (int j = 1; j <= i; j++)
                    {
                        if (i % j == 0)
                        {
                            count++;
                        }
                    }
                    if (count == 2)
                    {
                        sum += i;
                    }
                }

                return sum;
            }

            //输入参数对于函数而言,相当于已经赋值了的变量,直接可用。
            //输出参数相当于定义了一个变量,需要在函数中为其赋值,然后调用函数的时候将所赋值带出函数。
            public void shuchu(int a, out int b)
            {
                b = a + 10;
            }

            static void Main(string[] args)
            {
                HanShu hs = new HanShu();//函数所在类的初始化
                int sum = hs.SumZhiShu(100);//通过类来调用函数
                Console.WriteLine(sum);

                int c = 11;
                int d;
                hs.shuchu(c,out d);

                Console.WriteLine(d);

                Console.ReadLine();

  • 相关阅读:
    python运行错误---TabError: Inconsistent use of tabs and spaces in indentation
    python运行错误------Non-UTF-8 code
    opencv错误(Unhandled expection at at 0x0007EEE...)
    fatal error LNK1112: 模块计算机类型“X86”与目标计算机类型“x64”冲突——我的解决方案
    基础术语
    opencv
    图像归一化
    人脸相关数据库
    堆排序
    abp学习(二)
  • 原文地址:https://www.cnblogs.com/liuyuwen900326/p/4184164.html
Copyright © 2011-2022 走看看