BorislavBorisov

Loops N! / K!

Sep 30th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using System;
  2. class DividesTwoFactorials
  3. {
  4.     static void Main()
  5.     {
  6.         Console.Write("write N: ");
  7.         int N = int.Parse(Console.ReadLine());
  8.         Console.Write("write K: ");
  9.         int K = int.Parse(Console.ReadLine());
  10.         Factorial(N, K);
  11.         Console.WriteLine("N! / K! = {0}", Factorial(N, K));
  12.     }
  13.  
  14.     static long Factorial(int N, int K)
  15.     {
  16.         long factorial = 1;
  17.         for (int i = K + 1; i <= N; i++)
  18.         {
  19.             factorial = factorial * i;
  20.         }
  21.         return factorial;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment