黑暗之魂2全物品:帮个忙吧 改成C语言程序

来源:百度文库 编辑:高考问答 时间:2024/04/29 03:23:57
program ccc(input,oput);
const n=5;h=0.1;t=195584;
var i,j:integer;p,q:real;a,a1:array[1..n,1..n] of real;
m:longint;x,x1,f,b,b1:array[1..n] of real;
begin for i:=1 to n do
begin for j:=1 to n do read(a[i,j]);readln(b[i]);end;
{for i:=1 to n do
begin for j:=1 to n do a[i,j]:=1/(i+j-1);
b[i]:=0;for j:=1 to n do b[i]:=b[i]+j/(i+j-1);
end;}
readln;
a1:=a;b1:=b;x1:=b;m:=0;
repeat m:=m+1;writeln('m=',m);
for i:=1 to n do
begin f[i]:=-b[i];
for j:=1 to n do f[i]:=f[i]+a[i,j]*x1[j];
end;
for i:=1 to n do
begin p:=0;
for j:=1 to n do p:=p-a[i,j]*f[j];
x[i]:=x1[i]-f[i]*f[i]*(exp(h*p/f[i])-1)/p;
end;
x1:=x;
until n>=t;
for i:=1 to n do writeln('x[',i,']=',x[i]);
q:=0;
for i:=1 to n do
begin p:=0;
for j:=1 to n do p:=p+x[j]*a1[i,j];
p:=abs(b1[i]-p);q:=q+p;
end;
writeln('q=',q);readln;
end.

格式都没有了,很难辨认。和C差别比较大的函数我说一下吧:
writeln类似于cout,如
writeln('q=',q); 即 cout<<"q="<<q<<endl;
当然 printf("q=%d",q); 也是
a,a1:array[1..n,1..n] of real
即 float a[n+1],a1[n+1]
:=是赋值
for i:=1 to n 即 for(x=1;i<=n;i++)
a[i,j] 即 a[i][j]
{}中的是注释
配对的begin end 中夹的是语句块,相当于C中的{}
其他的应该没什么问题吧。