co ong nao khong giup toi voi toi dang can chuyen gap bai cua toi toi lam bai bang pascal roi nhung ma khong biet chuyen sang C nhu the nao day la nguon bai cua toi toi cam on rat nhieu va se hau ta xi để lại địa chỉ liên hệ uses crt; Type ptu=record ptc:string[10]; kieu: byte; gtri:real; End; var Tam:array[1..100] of ptu; Stack:array[1..100] of ptu; Hauto:array[1..100] of ptu; i,j,code,m,n,iso:integer; y:string; xso:string; ktra,mauso:boolean; thieu:boolean; tg,mu,so,x,code1:real; ch:char; Procedure luu_sohang(var xso:string); begin i:=i+1; Tam.ptc:=xso; Tam.kieu:=0; xso:=''''; end; Procedure Xlyxau(y:string); var j:integer; begin for j:=1 to length(y) do begin if (y[j]=''+'') or (y[j]=''-'') or (y[j]=''*'') or (y[j]=''/'') or (y[j]=''^'') or (y[j]=''('') or (y[j]='')'') then begin if (xso<>'''') then luu_sohang(xso); i:=i+1; Tam.ptc:=y[j]; if (y[j]=''('') or (y[j]='')'') then tam.kieu:=2 else Tam.kieu:=1; if (y[j]=''+'') or (y[j]=''-'') then Tam.gtri:=1; if (y[j]=''*'') or (y[j]=''/'') then Tam.gtri:=2; if (y[j]=''^'') then Tam.gtri:=3; end {--------------------------------} else begin xso:=xso+y[j]; if j=length(y) then luu_sohang(xso); end; end; writeln(''Cac phan tu cua bieu thuc:''); for j:=1 to i do write(tam[j].ptc:5); writeln; end; Procedure ktra_bthuc(i:integer); var j,k:integer; begin for j:=1 to i-1 do if (Tam[j].kieu=1) and (Tam[j+1].kieu=1) and (Tam[j+1].ptc<>''-'') then ktra:=false; for j:=1 to i do begin if (tam[j].kieu=0) then begin val(tam[j].ptc,tam[j].gtri,code); if code<>0 and not (tam[j].ptc[1] in [''a''..''z'',''A''..''Z'']) then ktra:=false; end; end; if ((tam[1].kieu=1) and (tam[1].ptc[1] in [''*'',''/'',''+''] )) or (tam.kieu=1) then ktra:=false; end; Procedure nhap_gtri(i:integer); var j,n:integer; tg:string; begin for j:=1 to i do if Tam[j].kieu=0 then begin val(Tam[j].ptc,tam[j].gtri,n); if n<>0 then begin write(''Nhap gia tri cho bien '',tam[j].ptc,'' :''); readln(tam[j].ptc); val(tam[j].ptc,tam[j].gtri,n); end; end; end; Procedure ChuyenHauto(i:integer); begin for j:=1 to i do begin if Tam[j].kieu=0 then begin m:=m+1; Hauto[m]:=Tam[j]; end; if Tam[j].ptc=''('' then begin n:=n+1; Stack[n]:=Tam[j]; end; if Tam[j].kieu=1 then begin while ((Stack[n].kieu=1) and (Stack[n].gtri>Tam[j].gtri)) do begin m:=m+1; Hauto[m]:=Stack[n]; n:=n-1; end; n:=n+1; Stack[n]:=Tam[j]; end; if Tam[j].ptc='')'' then begin while (Stack[n].ptc<>''('') and (n<>0) do begin m:=m+1; Hauto[m]:=Stack[n]; n:=n-1; end; if Stack[n].ptc=''('' then n:=n-1 else if Stack[n].ptc<>''('' then thieu:=true; end; end; while Stack[n].kieu=1 do begin m:=m+1; Hauto[m]:=Stack[n]; n:=n-1; end; if Stack[n].ptc=''('' then thieu:=true; end; Procedure TinhGtri(m:integer); begin for j:=1 to m do begin if Hauto[j].kieu=0 then begin n:=n+1; Stack[n]:=Hauto[j]; end; if Hauto[j].kieu=1 then begin if Hauto[j].ptc=''+'' then begin Stack[n-1].gtri:=Stack[n-1].gtri+Stack[n].gtri; n:=n-1; end; if Hauto[j].ptc=''-'' then begin Stack[n-1].gtri:=Stack[n-1].gtri-Stack[n].gtri; n:=n-1; end; if Hauto[j].ptc=''*'' then begin Stack[n-1].gtri:=Stack[n-1].gtri*Stack[n].gtri; n:=n-1; end; if Hauto[j].ptc=''/'' then begin if Stack[n].gtri=0 then begin mauso:=false; break; end; Stack[n-1].gtri:=Stack[n-1].gtri/Stack[n].gtri; n:=n-1; end; if Hauto[j].ptc=''^'' then begin mu:=Stack[n].gtri; tg:=1; for i:=1 to round(mu) do tg:=tg*Stack[n-1].gtri; Stack[n-1].gtri:=tg; n:=n-1; end; end; end; end; BEGIN ch:=''C''; Repeat m:=0;n:=0; ktra:=true; mauso:=true; thieu:=false; xso:=''''; clrscr; writeln(''---------CHUONG TRINH TINH GIA TRI BIEU THUC--------''); writeln; writeln(''Huong dan:''); writeln('' + Phep mu : ^''); writeln('' + Phep cong: +''); writeln('' + Phep tru : -''); writeln('' + Phep chia: /''); writeln('' + Phep nhan: *''); writeln('' + Nhap theo quy tac vd: 2*x^3+4/(3+5)+(x+7)^2''); writeln; writeln(''Nhap bieu thuc: ''); write(''y=''); readln(y); i:=0; Xlyxau(y); ktra_bthuc(i); if ktra=true then begin nhap_gtri(i); ChuyenHauto(i); if thieu=false then begin writeln; writeln(''Hau to gom cac phan tu :''); writeln; for j:=1 to m do begin if Hauto[j].kieu=0 then write('' '',Hauto[j].gtri:3:1); if Hauto[j].kieu=1 then write('' '',Hauto[j].ptc); end; n:=0; TinhGtri(m); writeln; writeln; if mauso=false then writeln(''Mau so khong the bang 0 .Hay kiem tra lai!'') else writeln(''Gia tri cua bieu thuc la: '',Stack[n].gtri:3:1); end else writeln(''Bieu thuc thieu dau ngoac!''); end else begin writeln; writeln(''Nhap bieu thuc khong dung.''); writeln(''Bieu thuc ban da nhap sai la : '',y); end; write(#10''Co tiep tuc khong(C/K)?''); ch:=upcase(readkey); Until ch=''K''; END.
Bác vào đây download chương trình convert từ Pascal to C về mà dùng nhé: http://www.synaptics.com/people/daveg/p2c-1.20.1.tar.gz Giải nén bằng Winrar xong bác có ngay một soft nhỏ thuận tiện, tha hồ mà convert. Chúc thành công.