Bob103

C#_for_Nigga_(V-2-№5)

Apr 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             Console.Write("Enter 'n':");
  6.             int n = int.Parse(Console.ReadLine());
  7.             Console.Write("Enter 'a':");
  8.             int a = int.Parse(Console.ReadLine());
  9.             Console.Write("Enter 'b':");
  10.             int b = int.Parse(Console.ReadLine());
  11.             Console.WriteLine("Number of dividers:{0}",num_div(n, a, b));
  12.         }
  13.  
  14.         public static int num_div (int n,int a,int b)
  15.         {
  16.             int k = 0;
  17.  
  18.             if(a==0)
  19.             {
  20.                 throw new DivideByZeroException();
  21.             }
  22.  
  23.             for (int i = a; i <= b; i++)
  24.             {
  25.                 if (n % i == 0)
  26.                 {
  27.                     k++;
  28.                 }
  29.  
  30.             }
  31.             return k;
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment