Viết chương trình cho phép chia hai đa thức để tìm đa thức thương

Viết chương trình cho phép chia hai đa thức để tìm đa thức thương

Viết chương trình cho phép chia hai đa thức để tìm đa thức thương và đa thức dư.

>> Viết chương trình cho phép nhân hai đa thức đã sắp xếp

>> Viết chương trình tính giá trị của đa thức A(x) với điều kiện không dùng biến mảng

Chương trình

Program Chia_da_thuc;

uses crt;

Type KM = array[0..10] of real;

Var A,B,C,AB,D: KM;

     i,n,cs,bc: byte;

Procedure NhapDT(Var A: KM; n:byte);

Var i: byte;

Begin

     For i:=n downto 0 do

     Begin Write('M[',i,']='); Read(A[i]);  End;

End;

Function BAC(A:KM;n:integer):Byte;

Var i:Byte;

Begin

    i:=n;

    While (A[i]=0) and (i> 0) do i:=i-1;

    BAC:=i;

End;


Procedure TRU(Var A:KM;B:KM;n:byte);

Var i: byte;

Begin

    For i:= 0 to n do A[i]:=A[i]-B[i];

End;

Procedure NHAN(Var C:KM;A,B:KM; Var n:byte);

Var i,j:byte;

    TAM:KM;

Begin

    n:=Bac(A,n)+Bac(B,n);

    For i:= 0 to 2*n do TAM[i]:=0;

    For i:= 0 to n do

       For j:=0 to n do TAM[i+j]:=TAM[i+j]+A[i]*B[j];

    For i:=0 to 2*n do C[i]:=TAM[i];

End;

Procedure INDT(A:KM;n:byte);

Var i: byte;

Begin

    if A[n] <> 0 then Write(A[n]:3:1,'x^',n);

    For i:=n-1 downto 0 do

     if A[i] <> 0 then

      if A[i] < 0 then write(A[i]:3:1,'x^',i) else Write('+',A[i]:3:1,'x^',i);

End;

Procedure DT_BAC(Var A:KM;Bac:byte;gt:real);

Var i:byte;

Begin

    For i:=1 to n do A[i]:=0;

    A[Bac]:=gt;

End;

Begin

     clrscr;

     Write('Nhap bac cua da thuc bi chia: ');Readln(n);

     Writeln('Nhap da thuc A: '); NhapDT(A,n);

     Writeln('Nhap da thuc B: '); NhapDT(B,n);

     clrscr;

     Write('Da thuc bi chia: ');Indt(A,n); Writeln;

     Write('Da thuc chia: ');Indt(B,n); Writeln;

     bc:=Bac(A,n)-Bac(B,n); {Luu bac cua da thuc C}

     For i:=1 to bc do C[i]:=0;

     While BAC(A,n) >= BAC(B,n) do

     Begin

         cs:=BAC(A,n)-BAC(B,n);

         C[cs]:=A[Bac(A,n)]/B[Bac(B,n)];

         Writeln('C[',cs,']=',C[cs]:3:1);

         DT_BAC(D,cs,C[cs]);Writeln;

         Write('Da thuc D:');

         Indt(D,n);

         NHAN(AB,B,D,n);Writeln;

         Write('Da thuc AB:');

         Indt(AB,n);Writeln;

         TRU(A,AB,n);

         Write('Da thuc A moi:');

         Indt(A,n);

     End;

     Writeln('Da thuc thuong: ');

     Indt(C,bc);

     Readln;

     Readln

End.
Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Export và import Drupal 7 nodes như thế nào ?

Export và import Drupal 7 nodes như thế nào ?

There are lots of ways to export configuration from one Drupal site and import into another; however, there are few ways to do the same with content. Here's a quick tip which has worked well for me.

Security, and Drupal như thế nào?

Security, and Drupal như thế nào?

Did you know I provide various infosec services, including security audits of code and infrastructure, penetration testing, etc, for Drupal websites?

Vô hiệu hoá bất kỳ hiệu ứng trực quan trong window 7

Vô hiệu hoá bất kỳ hiệu ứng trực quan trong window 7

Nếu bạn đang tìm kiếm một cách nâng cao tốc độ và hiệu suất, xin vui lòng làm theo những hướng dẫn này để có được Windows 7 với tốc độ cực nhanh! Hướng dẫn này thực sự có thể giúp bạn có được hiệu suất và tốc độ như là bạn mong muốn.

Công ty diệt chuột T&C

 

Diet con trung