Advertisement
huyhung94

Giải hệ phương trình tuyến tính( Tú - AT9B)

Sep 21st, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.60 KB | None | 0 0
  1. program baiso3;
  2. uses crt;
  3. type arr=array [1..1000] of real;
  4. var a,b:arr;
  5.     p,n,i,j:integer;
  6.     flag:byte;
  7.     traloi: char;
  8. function doi(x:integer; y:integer) : real;
  9. var k, th:integer;
  10. begin
  11.   th:=0;
  12.   for k:=0 to (x-1) do th:=th+k;
  13.   th:=th+y;
  14.   doi:=a[th];
  15. end;
  16. procedure yeucau;
  17.   begin
  18.   writeln('He phuong Trinh Tuyen Tinh');
  19.   writeln('You Are already');
  20.   write('Yes Or No: (Y/N) '); readln(traloi);
  21.   If traloi in ['y','Y'] then
  22.   begin
  23.   writeln('Nhap he phuong trinh vao de');
  24.   writeln('Any key to continute.......');
  25.   readln;
  26.   end;
  27.   end;
  28. procedure nhap;
  29. var dem:byte;
  30. begin
  31. begin
  32.   yeucau;
  33. end;
  34.   write('nhap so phuong trinh:'); readln(n);
  35.   p:=0;
  36.   for i:=1 to n do
  37.    begin
  38.      dem:=0;
  39.      write('Phuong trinh  ',i , ' : ');
  40.      writeln;
  41.      for j:=1 to i do
  42.        begin
  43.          write('  co he so thu ',j,' = ');
  44.          readln(a[p+j]);
  45.          if a[p+j]=0 then inc(dem);
  46.        end;
  47.      p:=p+i;
  48.      write('  Nhap he so ve phai b[',i,']=');
  49.      readln(b[i]);
  50.      if (a[p]=0) and (b[i]<>0) then flag:=1 ;
  51.      if (dem=i) and (b[i]=0) then flag:=2;
  52.    end;
  53. end;
  54. procedure tinhnghiem;
  55. begin
  56.   b[1]:=b[1]/doi(1,1);
  57.   for i:=2 to n do
  58.   begin
  59.     for j:=1 to i-1 do
  60.       b[i] := b[i]- (doi(i,j)*b[j]);
  61.     b[i]:=b[i]/doi(i,i);
  62.   end;
  63.   write('Nghiem cua he la:');
  64.   for i:=1 to n do
  65.     write(b[i]:0:2,' ');
  66. end;
  67. procedure giaihe;
  68. begin
  69.   if flag=1 then
  70.     write ('He phuong trinh vo nghiem')
  71.   else
  72.     if flag=2 then
  73.       write('He co vo so nghiem')
  74.   else
  75.     tinhnghiem;
  76. end;
  77. begin
  78.   clrscr;
  79.   nhap;
  80.   giaihe;
  81.   readln;
  82. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement