ellapt

6.4.FactorialsDivision

Dec 5th, 2012
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. using System;
  2. class FactorialsDivision
  3. {
  4. static void Main()
  5. {
  6. string strNum;
  7. int k;
  8. int n;
  9. int i;
  10. decimal kFactorial=1;
  11. decimal nFactorial=1;
  12.  
  13. do
  14. {
  15. Console.Write("Please, enter an integer number n > 1: ");
  16. }
  17. while (!int.TryParse(strNum = Console.ReadLine(), out n) || n <= 1);
  18.  
  19. do
  20. {
  21. Console.Write("Please, enter an integer number k > n: ");
  22. }
  23. while (!int.TryParse(strNum = Console.ReadLine(), out k) || k <=n);
  24.  
  25. for (i = 1; i <= n; i++)
  26. {
  27. nFactorial*=i;
  28. }
  29. for (i = 1; i <= k; i++)
  30. {
  31. kFactorial*=i;
  32. }
  33. Console.WriteLine("{0}!/{1}! = {2}", n, k, nFactorial/kFactorial);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment