Advertisement
svetoslavbozov

[C#-1.6.7] MoreFactorials

Dec 30th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. /*Write a program that calculates N!*K! / (K-N)! for given N and K (1<N<K).
  2. */
  3.  
  4. using System;
  5.  
  6.  
  7. class MoreFactorials
  8. {
  9.     static void Main()
  10.     {
  11.         Console.WriteLine("Enter two numbers k>n>1: ");
  12.         int n = int.Parse(Console.ReadLine());
  13.         int k = int.Parse(Console.ReadLine());
  14.         int result = 1;
  15.  
  16.         if ((n>1) && (k>n))
  17.         {
  18.             for (int i = k, j = 1; i > k - n; i--, j++)
  19.         {
  20.                 result *= i*j;              
  21.         }
  22.             Console.WriteLine(result);
  23.         }
  24.         else
  25.         {
  26.             Console.WriteLine("Invalid numbers");
  27.         }        
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement