Added everything from Kalmar
This commit is contained in:
39
20231018/ConsoleApp2/Program.cs
Normal file
39
20231018/ConsoleApp2/Program.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleApp2
|
||||
{
|
||||
public static class Intkiterjesztesek
|
||||
{
|
||||
public static int Factorial(this int szam)
|
||||
{
|
||||
if (szam < 0) {
|
||||
throw new ArgumentException("A negatív számoknak nincs faktoriálisa");
|
||||
}
|
||||
|
||||
if (szam == 0 || szam == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int result = 1;
|
||||
for (int i = 2; i <= szam; ++i) {
|
||||
result *= i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
class Program
|
||||
{
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int szam = 5;
|
||||
int factorial = szam.Factorial();
|
||||
Console.WriteLine($"{szam}! = {factorial}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user