Guest User

Untitled

a guest
Apr 24th, 2018
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 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 FactorialFinder
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             FactorialFinder();
  14.         }
  15.  
  16.         static void FactorialFinder()
  17.         {
  18.             Console.WriteLine("Please enter a positive integer");
  19.  
  20.             string input = Console.ReadLine();
  21.  
  22.             if (Int32.TryParse(input, out int n))
  23.             {
  24.                 if (n > 0)
  25.                 {
  26.                     int temp1;
  27.                     int temp2 = 1;
  28.                     int eq=0;
  29.  
  30.                     for (int i = 0; i <= n; i++)
  31.                     {
  32.                         temp1 = n - i;
  33.                         if (n - i == 0)
  34.                         {
  35.                             temp1 = 1;
  36.                         }
  37.                         eq = temp1 * temp2;
  38.                         temp2 = eq;
  39.                     }
  40.                     Console.WriteLine("You factorial equals: {0}", eq);
  41.                     Console.ReadKey();
  42.                 }
  43.                 else
  44.                 {
  45.                     Console.WriteLine("That's not a positive integer");
  46.                     Console.ReadKey();
  47.                 }
  48.             }
  49.             else
  50.             {
  51.                 Console.WriteLine("Thats not a number");
  52.                 Console.ReadKey();
  53.             }
  54.         }  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment