using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program //Ритуля
{
static int Fact(int a)
{
int rez = 1;
if (a > 0)
for (int i = 1; i <= a; i++)
{
rez *= i;
}
return rez;
}
static int Razm(int n, int k)
{
int rez;
rez = (Fact(n)) / (Fact(n - k));
return rez;
}
static int Soch(int n, int k)
{
int rez;
rez = (Fact(n)) / (Fact(k) * Fact(n - k));
return rez;
}
static int Pow(int n, int k)
{
int rez;
rez = n;
for (int i = 0; i < k - 1; i++)
{
rez *= n;
}
return rez;
}
static void Main(string[] args)
{
string input;
int res = 0;
double rez = 0;
A1:
Console.WriteLine("Наберите номер функции для ее выполнения.");
Console.WriteLine("1 - Перестановка без повторений, 2 - Перестановка с повторениями.");
Console.WriteLine("3 - Размещение без повторений, 4 - Размещение с повторениями.");
Console.WriteLine("5 - Сочетание без повторений, 6 - Сочетание с повторениями.");
input = Console.ReadLine();
if (input == "1")
{
Console.WriteLine("Перестановка 5 элементов без повторов.");
res = Fact(5);
Console.WriteLine(Convert.ToString(res));
Console.ReadKey();
Console.Clear();
goto A1;
}
else if (input == "2")
{
Console.WriteLine("Перестановка 5 элементов с повторами.");
res = Fact(5 - 1) * 5;
Console.WriteLine(Convert.ToString(res));
Console.ReadKey();
Console.Clear();
goto A1;
}
else if (input == "3")
{
Console.WriteLine("Размещение 5 элементов по 4 различным позициям без повторов.");
res = Razm(5, 4);
Console.WriteLine(Convert.ToString(res));
Console.ReadKey();
Console.Clear();
goto A1;
}
else if (input == "4")
{
Console.WriteLine("Размещение 5 элементов по 4 различным позициям с повторами.");
res = Pow(5, 4);
Console.WriteLine(Convert.ToString(res));
Console.ReadKey();
Console.Clear();
goto A1;
}
else if (input == "5")
{
Console.WriteLine("Сочетание 4 элементов из 5 возможных без повторов.");
res = Soch(5, 4);
Console.WriteLine(Convert.ToString(res));
Console.ReadKey();
Console.Clear();
goto A1;
}
else if (input == "6")
{
Console.WriteLine("Сочетание 4 элементов из 6 возможных с повторами.");
res = Soch(6, 4 - 1);
rez = 6 - 4 + 1;
rez = rez / 4;
rez = Soch(6, 4 - 1) * rez;
Console.WriteLine(Convert.ToString(rez));
Console.ReadKey();
Console.Clear();
goto A1;
}
}
}
}