把下列几个赋值语句合并成一个赋值语句_第1页
把下列几个赋值语句合并成一个赋值语句_第2页
把下列几个赋值语句合并成一个赋值语句_第3页
把下列几个赋值语句合并成一个赋值语句_第4页
把下列几个赋值语句合并成一个赋值语句_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1、把下列几个赋值语句合并成一个赋值语句: number:=2* number; number:=4- number; number:=7* number2、已知a、b、c、d、e、f、g均为整型变量,其值分别为2、4、6、8、10、12、14,请写出执行下面的写语句后的输出结果:(1)write(a,b,c); (2)writeln(a,b,c); write(d,e,f); writeln(d,e,f); write(g) writeln(g)(3)write(a,b); (4)writeln;writeln; write(a);write(c); write(b,c,d,e);write

2、ln(d,e); writeln(f)write(f)3、a1、a2、a3是布尔变量,分别等于true、true、false,计算下列表达式的值:(1)not a1 and not a2 (2)a1 or a2 and a3(3)(not a1 or a2)and (a2 or a3)(4)false or not a1 and a2 or not a34、把下面两个if语句合并成一个不嵌套的if语句:(1)if ab then x:=1 else x:=2; if a0 then if rate1 then a:=0 else a:=1 else a:=1;5、设k为整型变量,用case语句

3、重写下面的程序段: if (k0) then if k5 then if k2 then x:=3 else x:=46、比较下列各题中、两个程序段的输出:(1)for counter:=cto f do write(hello!); writeln(good-bye!) for counter:=cto f do begin write(hello!); writeln(good-bye!) end(2) for counter:=cto f do write(hello!) fff:=f; for counter:=cto fff do writeln(hello!)(3) for i:=

4、ctof do writeln(hello!);for i:=f downto c do writeln(hello!);(4)while(ab7、写出下列各程序段的输出结果 (1)program one; Var a,b:integer; Procedure proc1(x,y:integer); Begin x:=a+b; y:=a-b end; begin a:=1; b:=2; proc1(a,b); writeln(a,b) end. (2)program two; Var a,b:integer; Procedure proc2(x:integer;var y:integer);

5、Begin x:=a+b; y:=a-b end; begin a:=1; b:=2; proc2(a,b); writeln(a,b) end.(3)program three; Var a,b:integer; Procedure proc3(var x,y:integer); Begin x:=3; y:=4 end; begin a:=1; b:=2; proc3(a,b); writeln(a,b) end.(4)program four; Var a,b,c:integer; Procedure proc4; Var b:integer;Begin a:=1; b:=2; c:=3

6、 end; begin a:=101; b:=102; c:=103; proc4; writeln(a,b,c) end.8、阅读程序写结果(1) program s401;var p,q:array0.5 of integer;i,x,y:integer;beginy:=20;for i:=0 to 4 do read(pi);readln;q0:=(p0+p1)+(p2+p3+p4) div 7;q1:=p0+p1 div (p2+p3) div p4);q2:=p0*p1 div p2;q3:=q0*q1;q4:=q1+q2+q3;x:=(q0+q4+2)-p(q3+3) mod 4;

7、if (x10) theny:=y+(q1*100-q3) div (pp4 mod 3*5)elsey:=y+20+(q2*100-q3) div (pp4 mod 3*5);writeln(x,y);end./*注:本例中,给定的输入数据可以避免分母为0 或下标越界。*/输入:6 6 5 5 3输出:(2)program s402;var a,b:integer;x,y:integer;procedure fun(a,b:integer);var k:integer;begink:=a; a:=b; b:=k;end;begina:=3; b:=6;x:=a; y:=b;fun(x,y);

8、write(No.1:,a,b, );fun(a,b);writeln(No.2:,a,b);end.输出: (3)program S403;var a1:array1.50 of integer;var i,j,t,t2,n,n2:integer;beginn:=50;for i:=1 to n do a1i:=0;n2:=round(sqrt(n);for i:=2 to n2 doif(a1i=0) thenbegint2:=n div i;for j:=2 to t2 do a1i*j:=1;end;t:=0;for i:=2 to n doif (a1i=0) thenbeginwr

9、ite(i:4); inc(t);if(t mod 10=0) then writeln;end;writeln;end.输出:(4)program exp1;VAR i, s, max:integer; a :array1.10 of integer;Begin for i:=1 to 10 do read(ai); max:=a1; s:=a1; for i:=2 to 10 do begin if smax then max:=s end; writeln(max=,MAX)End.输入:8 9 1 24 6 5 11 15 28 9输出:max=(5)program exp2; CON

10、ST N=10;VAR S,I:INTEGER;FUNCTION CO(I1:INTEGER):INTEGER; VAR J1,S1:INTEGER; BEGIN S1:=N; FOR J1:=(N-1) DOWNTO (N-I1+1) DO S1:=S1*J1 DIV (N-J1+1); CO:=S1; END;BEGIN S:=N+1; FOR I:=2 TO N DO S:=S+CO(I); WRITELN(S=,S);END.(6)Program exp3; VAR I,J,S:INTEGER; B :ARRAY0.5 OF INTEGER;BEGIN S:=1; FOR I:=1 T

11、O 5 DO BI:=I; J:=1; WHILE J0 DO BEGIN J:=5; WHILE (J0) AND (BJ=10+J-5) DO J:=J-1; IF J0 THEN BEGIN S:=S+1; BJ:=BJ+1; FOR i:=J+1 TO 5 DO Bi:=BJ+i-J END; END; WRITELN(S=,S);END.(7)Program EXP4; const n=4;type se=array1.n*2 of char;var i,j,i1,j1,k,s,t,s1,L,swap:integer; temp :char; a :se;Begin for i:=1

12、 to n*2 do read(ai); readln; s:=0; t:=0; for i:=1 to n*2 do if ai=1 then s:=s+1 else if ai=0 then t:=t+1; if (sn) or (tn) then writeln(error) else begin s1:=0; for i:=1 to 2*n-1 do if aiai+1 then s1:=s1+1; writeln(jamp=,s1); swap:=0; for i:=1 to 2*n-1 do for j:=i+1 to 2*n do if aiaj then begin temp:

13、=ai;ai:=aj;aj:=temp; s:=0; for L:=1 to 2*n-1 do if aLaL+1 then s:=s+1; if sswap then begin swap:=s; i1:=i; j1:=j end; temp:=ai;ai:=aj;aj:=temp end; if swap0 then writeln(maxswap=,swap-s1, i=,i1, j=,j1) end End.输入:10101100 输出:9、完善程序木材加工题目描述:木材厂有一些原木,现在想把这些木头切割成一些长度相同的小段木头(木头有可能有剩余),需要得到的小段的数目是给定的。当然,

14、我们希望得到的小段越长越好,你的任务是计算能够得到的小段木头的最大长度。木头长度的单位是cm。原木的长度都是正整数,我们要求切割得到的小段木头的长度也是正整数。输入:第一行是两个正整数N和K(1 N 10000,1 K 10000),N是原木的数目,K是需要得到的小段的数目。接下来的N行,每行有一个1到10000之间的正整数,表示一根原木的长度。输出:输出能够切割得到的小段的最大长度。如果连1cm长的小段都切不出来,输出”0”。输入样例:3 7232124456输出样例:114程序:varn, k : integer;len : array 1.10000 of integer;i, left, right, mid : integer;function isok(t : integer) : boolean;varnum, i : integer;beginnum := 0;for i := 1 to n do beginif num = k then break;num := ;end;if then isok := trueelse isok := fal

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论