Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FactorialFinder
- {
- class Program
- {
- static void Main(string[] args)
- {
- FactorialFinder();
- }
- static void FactorialFinder()
- {
- Console.WriteLine("Please enter a positive integer");
- string input = Console.ReadLine();
- if (Int32.TryParse(input, out int n))
- {
- if (n > 0)
- {
- int temp1;
- int temp2 = 1;
- int eq=0;
- for (int i = 0; i <= n; i++)
- {
- temp1 = n - i;
- if (n - i == 0)
- {
- temp1 = 1;
- }
- eq = temp1 * temp2;
- temp2 = eq;
- }
- Console.WriteLine("You factorial equals: {0}", eq);
- Console.ReadKey();
- }
- else
- {
- Console.WriteLine("That's not a positive integer");
- Console.ReadKey();
- }
- }
- else
- {
- Console.WriteLine("Thats not a number");
- Console.ReadKey();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment