program stat;
uses crt;
var side: array [1..4] of real;
t0,tn:array[1..30,1..30] of real;
iv:integer;
procedure input;
var cnt :integer;
begin
clrscr;
writeln;
write('In how ');
readln(iv);
for cnt:=1 to 4 do
begin
write('temperature ',cnt,' side?');
readln(side[cnt]);
end
end;
procedure calc;
var eps:real;
cnt1,cnt2:integer;
abb :boolean;
procedure setmat0;
var tm:real;
cnt1,cnt2:integer;
begin
iv:=iv+1;
tm:=(side[1]+side[2]+side[3]+side[4])/4;
for cnt1 :=2 to iv-1 do
begin
t0[cnt1,1]:=side[1];
t0[iv,cnt1]:=side[2];
t0[cnt1,iv]:=side[3];
t0[1,cnt1]:=side[4];
end;
t0[1,1]:=(side[1]+side[4])/2;
t0[iv,1]:=(side[1]+side[2])/2;
t0[iv,iv]:=(side[2]+side[3])/2;
t0[1,iv]:=(side[3]+side[4])/2;
for cnt1:=2 to iv-1 do
for cnt2:=2 to iv-1 do
t0[cnt1,cnt2]:=tm;
end;
procedure setmatn;
var cnt1,cnt2:integer;
begin tn:=t0 end;
begin
fillchar(t0[1,1],5400,chr($00));
setmat0;
setmatn;
repeat
eps:=0.1;
abb:=true;
for cnt1:=2 to iv-1 do
for cnt2:=2 to iv-1 do
begin
t0[cnt1,cnt2]:=(tn[cnt1+1,cnt2]+tn[cnt1-1,cnt2]+tn[cnt1,cnt2+1]+tn[cnt1,cnt2-1])/4;
if abs(t0[cnt1,cnt2]-tn[cnt1,cnt2])> eps then abb:=false;
end;
setmatn
until abb
end;
procedure output;
var cnt1,cnt2:integer;
begin
writeln;
cnt2:=iv;
repeat
for cnt1:=1 to iv do
write(int(t0[cnt1,cnt2]+0.5):6:0);
cnt2:=cnt2-1;
writeln;
writeln;
until (cnt2<1)
end;
begin
input;
calc;
output;
Readln;
end.
вот на visual с++ 6.0
#include <iostream>
#include <cmath>
using namespace std;
#define min 4
#define max 30
int iv;
double eps;
int cnt1,cnt2;
bool abb;
double side[min];
double tn[max][max];
double t0[max][max];
void input();
void calc();
void setmat0();
void setmatn();
void output();
int main()
{
input();
calc();
output();
return 0;
}
void input()
{
cout << "In how many sub-intervals shall a side be subdivided ?" ;
cin >> iv;
for (int cnt=1; cnt<4; cnt++)
{
cout << " Temperature of the "<< cnt << ".side?";
cin >> side[cnt] ;
}
};
void calc()
{
t0[1][1]=5400;
setmat0();
setmatn();
do
{
eps=0.1;
abb= true;
for (cnt1=1; cnt1<iv-1; cnt1++)
for (cnt2=1; cnt2<iv-1; cnt2++)
{
t0 [cnt1 ] [cnt2 ] = (
tn [cnt1+1] [cnt2 ] +
tn [cnt1-1] [cnt2 ] +
tn [cnt1 ] [cnt2+1] +
tn [cnt1 ] [cnt2-1] ) /4;
if (abs(t0[cnt1,cnt2]-tn[cnt1,cnt2]) > eps) abb=false;
}
setmatn();}
while (abb);
}
void setmat0()
//======================
{
int cnt1,cnt2;
double tm;
iv++;
tm= (side[1]+side[2]+side[3]+side[4])/4;
for (cnt1=1; cnt1<iv-1; cnt1++)
{
t0[cnt1] [1]=side[1];
t0[iv] [cnt1]=side[2];
t0[cnt1] [iv]=side[3];
t0[1] [cnt1]=side[4];
}
t0[1] [1]=(side[1]+side[4])/2;
t0[iv] [1]=(side[1]+side[2])/2;
t0[iv] [iv]=(side[2]+side[3])/2;
t0[1] [iv]=(side[3]+side[4])/2;
for (cnt1=1; cnt1<iv-1; cnt1++)
for (cnt2=1; cnt2<iv-1; cnt2++)
t0[cnt1][cnt2]=tm;
void cetmatn();
}
void setmatn()
{
for (cnt1=1; cnt1<iv-1; cnt1++)
for (cnt2=1; cnt2<iv-1; cnt2++)
tn[cnt1][cnt2]=t0[cnt1][cnt2];
}
void output()
{
int cnt1,cnt2;
cnt2=iv;
for (cnt1=0; cnt2<1; cnt1++)
cout << (t0[cnt1] [cnt2]) +0.5 ;
cnt2=cnt2-1;
}
c++ я изучаю только 2 с половиной месяца