Advertisement
callumbinner22

task 7

Nov 6th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter to numbers to satisfy K and N. 1< N< K");
  14.             Console.WriteLine("K:");
  15.             int K = int.Parse(Console.ReadLine());
  16.             Console.WriteLine("N:");
  17.             int N = int.Parse(Console.ReadLine());
  18.  
  19.             if (K < N || N < 1 || K<1)
  20.             {
  21.                 Console.WriteLine("Something went wrong! This does not satisfy the condition! ");
  22.                 return;
  23.  
  24.             }
  25.  
  26.             int factorial = 1;
  27.             for (int i = K - N + 1; i <= K; i++)
  28.             {
  29.                 factorial *= i;
  30.  
  31.                 if (i == K)
  32.                 {
  33.                     i = 2;
  34.  
  35.                     while (i <= N)
  36.                     {
  37.                         factorial *= i;
  38.                         i++;
  39.                     }
  40.                     break;
  41.                 }
  42.             }
  43.             Console.WriteLine("\n The factorial is: {0}!*{1}!/{1}-{0} = {2}\n", N, K, factorial);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement