get Number Of Divisors - CSharp System

CSharp examples for System:Math Number

Description

get Number Of Divisors

Demo Code


using System;/*from   w  w w. j a  v  a  2  s  .  c o m*/

public class Main{
        public static int getNumberOfDivisors(int n) {
         var numberOfDivisors = 0;
         var current = 1;
         var currentThreshold = n;

         while (current < currentThreshold) {
            if (n % current == 0) {
               currentThreshold = n / current;
               numberOfDivisors += 2;
            }

            current++;
         }

         return numberOfDivisors;
      }
}

Related Tutorials