Advertisement
tissiana

FactorialDivision

Oct 24th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 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 FactorialDivision
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             double firstNumber = double.Parse(Console.ReadLine());      
  14.             double secondNumber = double.Parse(Console.ReadLine());
  15.            
  16.             double result = CalculateFirstNumberFactorial(firstNumber) / CalculateSecondNumberFactorial(secondNumber);
  17.             Console.WriteLine($"{result:f2}");
  18.         }
  19.         public static double CalculateFirstNumberFactorial(double firstNumber)
  20.         {
  21.             double factorial = 1;
  22.  
  23.             for (double i = firstNumber; i >= 1; i--)
  24.             {
  25.                 factorial *= i;
  26.             }
  27.             if(firstNumber == 0)
  28.             {
  29.                 factorial = 1;
  30.             }
  31.             return factorial;
  32.         }
  33.         public static double CalculateSecondNumberFactorial(double secondNumber)
  34.         {
  35.             double factorial = 1;
  36.  
  37.             for (double j   = secondNumber; j >= 1; j--)
  38.             {
  39.                 factorial *= j;
  40.             }
  41.  
  42.             if(secondNumber == 0)
  43.             {
  44.                 factorial = 1;
  45.             }
  46.  
  47.             return factorial;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement