https://pastein.ru/t/gb
скопируйте уникальную ссылку для отправки
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static double stepen(double a, int b)
{
double output = 1;
for (int i = 0; i < b; i++)
{
output = output * a;
}
return output;
}
static void Main(string[] args)
{
double p = 10.0 / 13.0;
double q = 3.0 / 13.0;
double sum = 0;
double[] x = new double[4];
Console.WriteLine($"p = {p} ; q = {q}");
for (int i = 0; i < 3; i++)
{
x[i] = stepen(p, i) * q;
Console.WriteLine($"Вероятность P({i+1}) = {x[i]};");
sum += x[i];
}
x[3] = stepen(p, 3) * q + stepen(p, 4);
Console.WriteLine($"Вероятность P(4) = {x[3]};");
sum += x[3];
Console.WriteLine();
double Mx = x[0] * 1 + x[1] * 2 + x[2] * 3 + x[3] * 4;
double Mx2 = x[0] * 1 + x[1] * 4 + x[2] * 9 + x[3] * 16;
double Dx = Mx2 - (Mx * Mx);
double ox = Math.Sqrt(Dx);
Console.WriteLine("X\t|\t1\t\t\t2\t\t\t3\t\t\t4\t\t\tSum");
Console.WriteLine($"p\t|\t{x[0]}\t{x[1]}\t{x[2]}\t{x[3]}\t{sum}");
Console.WriteLine($"X * p\t|\t{x[0] * 1}\t{x[1]* 2}\t{x[2] * 3}\t{x[3]* 4}\t{Mx}");
Console.WriteLine($"X^2 * p\t|\t{x[0] * 1}\t{x[1] * 4}\t{x[2] * 9}\t{x[3] * 16}\t{Mx2}");
Console.WriteLine();
Console.WriteLine($"M(x) = {Mx}");
Console.WriteLine($"D(x) = Mx2 - (Mx)2 = {Dx}");
Console.WriteLine($"o(x) = {ox}");
Console.WriteLine();
Console.WriteLine($"P(X >= 2) = {x[1] + x[2] + x[3]}");
Console.WriteLine($"P(X >= 2) = {1 - x[0]}");
Console.WriteLine();
Console.WriteLine(x[0]);
Console.WriteLine(x[0] + x[1]);
Console.WriteLine(x[0] + x[1] + x[2]);
Console.WriteLine(x[0] + x[1] + x[2] + x[3]);
}
}
}