Here the code is obtained, it seems to be correct, BUT, according to the logic, it must first consider Y1 and then Y2, then the values ​​that we got should subtract. But what I get is Y1 does not count yields, and does not take away the value. Where did I make a mistake?

program RIAD; var i, j, n1, n2: integer; Y1, Y2, Y3: real; begin write('vvedite n1= '); readln(n1); write('vvedite n2= '); readln(n2); Y1 := 1; for i := 3 to n1 - 1 do Y1 := Y1 + (1) * 1 / i; writeln('Y1=', Y2:8:4); Y2 := 1; for j := 2 to n2 do Y2 := Y2 + (1) * 1 / i; writeln('Y1=', Y2:8:4); readln; Y3 = Y1 - Y2; writeln(Y3); end. 

    1 answer 1

    You seem to have mixed up the variable names simply:

     program RIAD; var i, j, n1, n2: integer; Y1, Y2, Y3: real; begin write('vvedite n1= '); readln(n1); write('vvedite n2= '); readln(n2); Y1 := 1; for i := 3 to n1 - 1 do Y1 := Y1 + (1) * 1 / i; writeln('Y1=', Y1:8:4); Y2 := 1; for j := 2 to n2 do Y2 := Y2 + (1) * 1 / i; writeln('Y2=', Y2:8:4); readln; Y3 := Y1 - Y2; writeln(Y3); end. 

    IDEONE

     n1 := 5; n2 := 6; 

    for example, variables are initialized explicitly:

     vvedite n1= vvedite n2= Y1= 1.5833 Y2= 2.2500 Y3= -0.6667 
    • Wow, thanks, but how to make it take away these values? - BraFik
    • It takes away, missed : after Y3 - Akubik
    • wait, in the code that you gave me a colon because there is, I compiled it. Still it doesn't take away - BraFik
    • supplemented the answer, on IDEONE Y3 is calculated correctly - Akubik
    • Ty and the truth, thank you, this can mean something for me with a compiler. - BraFik