get Triangle Number - CSharp System

CSharp examples for System:Math Number

Description

get Triangle Number

Demo Code


using System;//from w  w  w  . ja v  a2s  .com

public class Main{
    public static int getTriangleNumber(int n) {
         var triangleNumber = 0;

         for (var i = 1; i <= n; i++) {
            triangleNumber += i;
         }

         return triangleNumber;
      }
}

Related Tutorials