ToDiR0S

CalculateNAndK

Aug 16th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. // 06. Write a program that calculates n! / k! for given n and k (1 < k < n < 100). Use only one loop.
  2. using System;
  3.  
  4. class CalculateNK
  5. {
  6.     static void Main()
  7.     {
  8.         byte n = byte.Parse(Console.ReadLine());
  9.         byte k = byte.Parse(Console.ReadLine());
  10.         int nFact = 1;
  11.         int kFact = 1;
  12.  
  13.         for (int i = 1; i <= n; i++)
  14.         {
  15.             nFact = nFact * i;
  16.             if (i <= k)
  17.             {
  18.                 kFact = kFact * i;
  19.             }
  20.         }
  21.  
  22.         Console.WriteLine(nFact/kFact);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment