编程语言
首页 > 编程语言> > C#练习题答案: 草蜢 - 求和【难度:0级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

C#练习题答案: 草蜢 - 求和【难度:0级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

作者:互联网

草蜢 - 求和【难度:0级】:

答案1:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      return num*(num+1)/2;
    }
}​

答案2:

public static class Kata 
{
    public static int summation(int num)
    {
        return num*(num + 1)/2;
    }
}​

答案3:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      return (num*(num+1))/2;
    }
}​

答案4:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      //Code here
      return (num * (num+1)) / 2;
    }
}​

答案5:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      //Code here
      return num*(num+1)/2;
    }
}​

答案6:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
 
      return (num * (num+1) /2);
      
    }
}​

答案7:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      //Code here
      return ((num * (num + 1))/2);
    }
}​

答案8:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      return ((num * (num + 1))/2);
    }
}​

答案9:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      return (num*(num + 1))/2;
      //Code here
    }
}​

答案10:

using System;
using System.Linq;

public static class Kata 
{
    public static int summation(int num)
    {
      return Enumerable.Range(1, num).Sum();
    }
}​

答案11:

using System;
using System.Linq;

public static class Kata 
{
    public static int summation(int num)
    {
      //Code here
      return Enumerable.Range(1, num).Sum();
    }
}​

答案12:

using System.Linq;

public static class Kata 
{
    public static int summation(int num)
    {
      return Enumerable.Range(1, num).ToArray().Sum();
    }
}​

答案13:

using System.Linq;

public static class Kata 
{
    public static int summation(int num)
    {
      //Code here
      return Enumerable.Range(1, num).ToArray().Sum();
    }
}​

答案14:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      var result = 0;
  
      for (var i = 0; i <= num; i++)
      {
          result += i;
      }
  
      return result;
    }
}​

答案15:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      return (1 + num) * num / 2;
    }
}​

答案16:

public static class Kata
{
    public static int summation(int num)
    {
        return (1 + num) * num / 2;
    }
}​

答案17:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      //Code here
      return (1+num)*num/2;
    }
}​

答案18:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      int x = 0;
      for(int counter=0 ; counter <= num ; counter++) 
        {
        x = x + counter;
        }
    return x;
    }
}​

答案19:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
      if ( num == 1 ) {
        return num;
      } else {
        return num + summation (num - 1);
      }
    }
}​

答案20:

using System;

public static class Kata 
{
    public static int summation(int n)
    {
      return n * (n + 1) / 2;
    }
}​

答案21:

public static class Kata  {
  public static int summation(int n) {
    return n * (n + 1) / 2;
  }
}​

答案22:

using System;

public static class Kata 
{
    public static int summation(int n)
    {
      return (n * (n + 1)) / 2;
    }
}​

答案23:

using System;

public static class Kata 
{
    public static int summation(int num) => num != 1 ? num + summation(num-1) : 1;
}​

答案24:

using System;

public static class Kata 
{
    public static int summation(int num)
    {
         int[] arrlist = new int[num];
            int sum = 0;
            for (int n = 0; n <= arrlist.Length; n++)
            {
                sum += n;
            }
            return sum;
    }
}​




标签:练习题,景越,C#,class,int,num,static,summation,public
来源: https://blog.csdn.net/weixin_45444821/article/details/102750620