>>553です。ありがとうございます。 教えていただいたプログラムに549ー550を加えてみました。 Program Viva2chan; const maxvar = 'c'; type pnode= ^node; node = record value : boolean; term : string; next : pnode end; var stack : pnode; variables : array ['a'..maxvar] of boolean; i : integer; s : string; c : char;
procedure push(v : boolean); var nd : pnode; begin new(nd); nd^.value := v; nd^.next := stack; stack := nd end;
function pop : boolean; var v : boolean; nd : pnode; begin nd := stack; v := nd^.value; stack := nd^.next; pop := v; dispose(nd) end;
556 名前:デフォルトの名無しさん [2007/08/07(火) 15:52:20 ]
procedure ope(operation : char); var operand : boolean; begin if operation in ['&', '|'] then operand := pop; with stack^ do case operation of '&' : value := value and operand; '|' : value := value or operand; '\' : value := not value end end;
557 名前:デフォルトの名無しさん [2007/08/07(火) 15:53:13 ]
function disp(source : string) : string; var i : integer; c : char; begin for i := 1 to length(source) do begin c := source[i]; if c in ['a'..maxvar] then pusht(c) else if c in ['&', '|', '#', '\'] then term(c) end; disp := popt end;
function powerof(n : integer) : integer; begin if n > 0 then powerof := powerof(pred(n)) * 2 else powerof := 1 end;
begin stack := nil; write('Enter term :'); readln(s); for i := 1 to powerof(ord(maxvar) - ord('a') + 1) do begin SetVarSet(i); for c := 'a' to maxvar do write(variables[c], ' '); writeln(calc(s)) end end.
558 名前:デフォルトの名無しさん [2007/08/07(火) 15:54:01 ]
5ー7行目を549のように書き換えました。 60ー83行目に549ー550を追加しました。 コンパイルすると push, pop, ope, calc, SetVarSet, term "datakozo.p", line 62: Warning: Symbol 'POPT' is not defined [221] "datakozo.p", line 62: Warning: Mixing non-strings with strings [170] , disp "datakozo.p", line 80: Warning: Symbol 'PUSHT' is not defined [221] "datakozo.p", line 83: Warning: Symbol 'POPT' is not defined [221] "datakozo.p", line 83: Warning: Mixing non-strings with strings [170] , powerof, Viva2chan
program EX01(input,output); var D1,D2,S,D,P,Q:integer; begin read(D1,D2); S:=D1+D2;D:=D1-D2;P:=D1*D2;Q:=D1 dir D2; writeln(D1,D2); writeln(S,D,P,Q); end. 整数の四則演算なのですが、Windowsで保存するときの拡張子を教えてください。
コマンドプロンプトでは、 C:\Documents and Settings\user>cd My Documents C:\Documents and Settings\user\My Documents>bcc32 EX01.pas C:\Documents and Settings\user\My Documents>EX01.exe って感じでおkですか?
てへ、もういっちょ教えてくださいw さっきのを、整数じゃなくて実数にするのですが、 program PR01(input,output); real D1,D2,S,D,P,Q:integer; begin read(D1,D2); S:=D1+D2;D:=D1-D2;P:=D1*D2;Q:=D1/D2; writeln(D1,D2); writeln(S,D,P,Q); end. だとエラーが出るんですけど、どこが違うのでしょう?
program PR0203(input,output); var W,L,H,V,S:integer; begin readln(W,L);raldln(H);writeln(W,L,H); V:=W*L*H;S:=2*(W*(L+H)+L*H); writeln(V,S); end.
これでエラーが出るのは何故なんでしょう?
PR0203.pas(4,21) Error: Identifier not found "raldln" PR0203.pas(4,24) Error: Illegal expression PR0203.pas(4,25) Warning: Variable "H" does not seem to be initialized PR0203.pas(8) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted Error: C:\FPC\2.2.0\bin\i386-Win32\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled)
program PR0331(input,output); var D1,D2:real; var T1,T2,T3,T4,R1,R2,R3,R4:integer; begin read(D1,D2); T1:=trunc(D1);T2:=trunc(D2);T3:=trunc(-D1);T4:=trunc(-D2); R1:=round(D1);R2:=round(D2);R3:=round(-D1);R4:=round(-D2); writeln('trunc(',D1:2:1,')=',T1:2,'trunc(',D2:2:1,')=',T2:2,'trunc(',-D1:2:1,')=',T3:2,'trunc(',-D2:2:1,')=',T4:2); writeln('round(',D1:2:1,')=',R1:2,'round(',D2:2:1,')=',R2:2,'round(',-D1:2:1,')=',R3:2,'round(',-D2:2:1,')=',R4:2); end.
writeln('Data Entered : ', D1, D2); writeln('Trunc''s of them are ', trunc(D1), ' and ', trunc(D2), ' respectivly.'); writeln('Trunc''s of negated them are ', trunc(-D1), ' and ', trunc(-D2), ' respectivly.'); writeln('Round''s of them are ', round(D1), ' and ', round(D2), ' respectivly.'); writeln('Round''s of negated them are ', round(-D1), ' and ', round(-D2), ' respectivly.'); writeln('Thus, both functions are (different from / same for) each other in case of (you must fill this parenthesis ).')
605 名前:デフォルトの名無しさん [2007/10/09(火) 21:31:21 ]
program PR0331(input,output); const D1=0.4;D2=0.5;D3=-0.4;D4=-0.5; var T1,T2,T3,T4,R1,R2,R3,R4:integer; begin T1:=trunc(D1);T2:=trunc(D2);T3:=trunc(D3);T4:=trunc(D4); R1:=round(D1);R2:=round(D2);R3:=round(D3);R4:=round(D4); writeln('trunc(',D1:4:1,')=',T1:2,' trunc(',D2:4:1,')=',T2:2,' trunc(',-D1:4:1,')=',T3:2,' trunc(',-D2:4:1,')=',T4:2); writeln('round(',D1:4:1,')=',R1:2,' round(',D2:4:1,')=',R2:2,' round(',-D1:4:1,')=',R3:2,' round(',-D2:4:1,')=',R4:2); end.
program PR0311(input,output); ver D1,D2:integer; ver O1,O2,E1,E2:Boolean; begin read(D1,D2); O1:=odd(D1);D2:=odd(D2); E1:=even(D1);E2:=even(D2); writeln(' odd(',D1,')=',O1);writeln(' odd(',D2,')=',O2); writeln('even(',D1,')=',E1);writeln('even(',D2,')=',E2); end.
program PR0311(input,output); ver D1,D2:integer; begin read(D1,D2); writeln(' odd(',D1,')=',odd(D1));writeln(' odd(',D2,')=',odd(D2)); writeln('even(',D1,')=',even(D1));writeln('even(',D2,')=',even(D2)); end.
エラーメッセージ Free Pascal Compiler version 2.2.0 [2007/09/09] for i386 Copyright (c) 1993-2007 by Florian Klaempfl Target OS: Win32 for i386 Compiling PR0311.pas Fatal: Syntax error, "BEGIN" expected but "identifier VER" found Fatal: Compilation aborted Error: C:\FPC\2.2.0\bin\i386-Win32\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled)
Program Viva2chan(output); type courses = (programming, algebra, circuit, english, electromagnetics); coursset = set of courses; var studentA, studentB, studentC : coursset;
procedure DispSet(s : coursset); begin if programming in s then write('Programming'); if algebra in s then write('Algebra'); if circuit in s then write('Circuit'); if english in s then write('English'); if electromagnetics in s then write('Electromagnetics'); writeln end;
function factrial(i:integer): real; begin if n=1 then begin factrial := 1; end else begin factrial := i*factrial(i-1); end; begin write('Enter n : '); readln(n); For i:=1 to n do begin ANS:=1+(1/factrial); end; end;
function factrial(i:integer): real; begin if n=1 then begin factrial := 1; end else begin factrial := i*factrial(i-1); end; begin write('Enter n : '); readln(n); For i:=1 to n do begin ANS:=ANS+(1/factorical(i)); end; end; begin
function factorial(i:integer) : real; begin if i = 1 then factorial := 1 else factorial := i * factorial(i - 1) end; begin write('Enter n : '); readln(n); For i := 1 to n do ANS := ANS + (1. / factorial(i)); writeln('N = ', n, ' ANS = ', ANS:8:6); readln; end.