主题:帮我找找错误!!!!!!!!!!
题目是这样子的
s(x,n)
y= -------------------
s(x+1.75,n)+s(x,n+5)
x2(次方) x3 xn
s(x,n)=x+ ---- + --- + ~~~~~~~+ ----
2 3 n
用函数和过程两种方法作
以下是我自己编的两种方法 输入相同的x,n,但运行起来答案不一样,帮帮找找错误
函数
program xiti;
var n:integer;
x,y:real;
function s(x:real;n:integer):real;
var i,j:real;
k:integer;
begin
i:=x;
j:=x;
for k:=2 to n do
begin
i:=i*x;
j:=j+i/k;
end;
s:=j;
end;
begin
readln(x,n);
y:=s(x,n)/(s(x+1.75,n)+s(x,n+5));
writeln(y);
end.
过程
program xiti;
var n:integer;
x,y,s1,s2,s3:real;
procedure s(x:real;y:integer;var c:real);
var sum:real;
i:integer;
begin
sum:=x;
c:=x;
for i:=2 to n do
begin
sum:=sum*x;
c:=c+sum/i;
end;
end;
begin
readln(x,n);
s(x,n,s1);
s(x+1.75,n,s2);
s(x,n+5,s3);
y:=s1/(s2+s3);
writeln(y);
readln;
end.
s(x,n)
y= -------------------
s(x+1.75,n)+s(x,n+5)
x2(次方) x3 xn
s(x,n)=x+ ---- + --- + ~~~~~~~+ ----
2 3 n
用函数和过程两种方法作
以下是我自己编的两种方法 输入相同的x,n,但运行起来答案不一样,帮帮找找错误
函数
program xiti;
var n:integer;
x,y:real;
function s(x:real;n:integer):real;
var i,j:real;
k:integer;
begin
i:=x;
j:=x;
for k:=2 to n do
begin
i:=i*x;
j:=j+i/k;
end;
s:=j;
end;
begin
readln(x,n);
y:=s(x,n)/(s(x+1.75,n)+s(x,n+5));
writeln(y);
end.
过程
program xiti;
var n:integer;
x,y,s1,s2,s3:real;
procedure s(x:real;y:integer;var c:real);
var sum:real;
i:integer;
begin
sum:=x;
c:=x;
for i:=2 to n do
begin
sum:=sum*x;
c:=c+sum/i;
end;
end;
begin
readln(x,n);
s(x,n,s1);
s(x+1.75,n,s2);
s(x,n+5,s3);
y:=s1/(s2+s3);
writeln(y);
readln;
end.