I don't understand the sigma notation and for loop

后端 未结 7 519
忘掉有多难
忘掉有多难 2021-01-05 04:10

I have the book saying that

\"enter

and says that this is equivalent to saying

相关标签:
7条回答
  • 2021-01-05 04:42

    About the second sum, it starts at k=j and ends at i. That sum is not equal to (j - i - 1), instead, it's equal to (i - j + 1). Let's do an example :

    If j = 3 and i = 6, then k = 3 and sum = 1+1+1+1 = 4. By applying the formula : sum = (i - j + 1) = 6 - 3 + 1 = 4.

    Now, the C code for the first example, they said :

    for(i = 1; i <= N; i++) Sum += i;

    This is wrong. Instead, it should be :

    for(i = 1; i <= N; i++)
        Sum += 1;
    

    In the second one, they said :

    for(k = j; k <= 1; k++) Sum += k;

    Instead, it should be :

    for(k = j; k <= i; k++)
        Sum += 1;     // Where i >= j
    
    0 讨论(0)
提交回复
热议问题