K
K
kos_dev2021-10-07 12:26:52
Mathematics
kos_dev, 2021-10-07 12:26:52

How to transfer a mathematical formula to a program?

Hello, there is a formula
615ebbb2b966e657589573.png

. Am I implementing it correctly in the code or am I mistaken?

The code

for(int i = 0; i < foundLettersFrequency.size(); i++)
{
    double letterFrequency = foundLettersFrequency[i];
    double stringLength = 10; // Длина строки находится иначе. это для упрощения
    // Сама формула, на каждой итерации цикла - Верно ли?
    double IC = letterFrequency * (letterFrequency - 1) / stringLength * (stringLength - 1);
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2021-10-07
@kos_dev

You are wrong. Division and multiplication are equal left associative operations.
And there is no summation in your loop.

H
hint000, 2021-10-07
@hint000

1. declaring variables inside the loop hurts the eye, fu.
2. IC is not initialized to zero before the loop, as a result the variable may have a random value.
3. IC += ... you need the sum, but where do you have the summation?
4.

double stringLength = 10; // The length of the string is found differently. this is to simplify
real string length??

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question