Answer the question
In order to leave comments, you need to log in
Who will tell you how to add two cyclic sums, what is wrong with me when they are added?
Task
The program before procedure Sum1 is correct, on procedure Sum1 it knocks out an instruction error, what's wrong?
Program Func;
Type func=function(x:integer):real;
Var S1,S2:real;
n1,m1,n2,m2:integer;
r:text;
{$F+}
Function f1(x:integer):real;
Begin
f1:=(x+2)/(x+5);
End;
Function f2(x:integer):real;
Begin
f2:=5/(x*x)-ln(x)/ln(10);
End;
{$F-}
Procedure Sum(n,m:integer;f:func;Var S:real);
Var x:integer;
Begin
S:=0;
For x:=n to m do S:=S+f(x);
End;
Begin
Assign(r,'res7-ind');Rewrite(r);
Writeln('n1,m1=');Readln(n1,m1);
Sum(n1,m1,f1,S1);
Writeln(r,'S1=',S1:8:5);
Writeln('n2,m2=');Readln(n2,m2);
Sum(n2,m2,f2,S2);
Writeln(r,'S2=',S2:8:5);
Procedure Sum1;
Var Sum1:real;
Begin
Sum1:=0;
Sum1:=S1+S2;
End;
Sum1(S1,S2);
Writeln (r,'Sum1=',Sum1:8:5);
Close(r);
End.
Answer the question
In order to leave comments, you need to log in
Why is sum a procedure and not a function? She considers 1 value. And then it is possible so
Sum(n1,m1,f1) + Sum(n2,m2,f2)
Also it is not clear why Sum1. And what happens there ... She does not display S3. And to add the two results, a separate procedure is hardly needed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question