Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Examples
- {
- internal static class FactorialProgram
- {
- public static int Factorial(this int number)
- {
- if (number < 0) throw new ArgumentException("negative Zahl!");
- return number > 1 ? number * Factorial(--number) : 1;
- }
- public static void Main(string[] args)
- {
- Console.Write("Nicht-negative ganze Zahl: ");
- int value;
- if (!int.TryParse(Console.ReadLine(), out value)) return;
- Console.Write("{0}! = {1}", value, value.Factorial());
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement