Pascal if語句
你的語句:
if(m>0) then
w[i]:=b[m-1]
else
w[i]:=b[0];
a[m-1] := a[m-1]-1;
實際上是下面的兩個語句:
if(m>0) then w[i]:=b[m-1] else w[i]:=b[0];
a[m-1] := a[m-1]-1;
第一個語句是IF語句,根據m的值選擇執行一個操作:給w[i]賦不同的值。第二個語句是賦值語句,無論第一個語句的條件和結果如果都要執行。
如果需要在if語句的then或者else里面執行多條語句,應該使用begin 。.. end這樣的語法,否則then和else都只執行語句。
此外,你的語句里面的分號、冒號好像是中文的,電腦只允許使用英文。
用pascal語言中的if語句解決一下幾個問題
1.要確認A能不能被B整除,只要A除B的余數=0,那么他就能被B整除。
否則就輸出A,除號,B,等號,商(用整除函數DIV),再用A-B*商。程序:Var a,b:integer;Begin Readln(a,b); If a mod b=0 then Write(a,'/',b,'=',a div b) Else Write(a,'/',b,'=',a div b,'。
。',a-b*(a div b));End.3.先讀入這三個數,然后分別看看是不是偶數,是就偶數計數器加1,然后統計。
程序:Var a,b,c:integer; a1,b1,c1:boolean;Begin Readln(a,b,c); a1:=a mod 2=0; b1:=b mod 2=0; c1:=c mod 2=0; If ((a1 xor b1) and c1) or ((a1 xor c1) and b1) or ((b1 xor c1) and a1)then Write('YES') Else Write('NO');End.4.圓內的范圍是(2,2),圓上的范圍是(2,1)或(1,2),圓外就是除了這兩種情況。Var i,j:integer;Begin Readln(i,j); If (i=2) and (j=2) then Write('In') Else If ((i=1) and (j=2))or((i=2)and(j=1))then Write('On') Else Write('out');End.先做這么多,樓主先等等,謝。
望采納。
pascal三項IF語句如何用
if (條件) then (語句1) [else (語句2)];
就是計算條件表達式,如果為真(True),那么執行語句1,方括號[]內的語句可以不要,如果存在else語句,那么執行語句2
舉個例子:
var
a:longint;
begin
read(a);//讀入一個數
if (a=1) then writeln('a=1')//如果輸入的數是1,那么輸出a=1
else writeln('a1');//否則輸出a1
end.
轉載請注明出處華閱文章網 » pascalif語句