2001年4月全国高等教育自学考试高级语言程序设计试题
|
|
|
|
|
|
2.计算程序2 如下: program calc2(input,output); type st=set of 1..10; var s1:st; i:1..10;sum,k:integer; begin sum:=0;s1:=[]; for k:=1 to 5 do begin read(i);s1:=s1+[i] end; for i:=1 to 10 do begin if i in s1 then sum:=sum+i; if(i in s1)and(i mod 2=0)then write(i:3) end; writeln; writeln(’sum=’,sum) end. 当程序运行输入2 5 7 8 4 时,其输出为: 3.计算程序3 如下: program calc3(input,output); type rec=record a:=array [1..10] of integer; end; ptc=^rec; var i:integer;p:ptc; begin new(p) for i:=1 to 10 do begin read(p^.a[i]); if p^.a[i]>0 then write(p^.a[i]:3) end; writeln; dispose(p) end. 当程序运行输入-2 -5 6 -4 -8 12 23 -32 9 -4时,其输出为: 六、编程题(第1 题12 分,第2 题13 分,共25 分) 其中斜列上安排数的方向由up 控制,即 [程序] program prg2; const m=20; type ta=array[1..m,1..m]of integer; var a:ta; i,j,k,n:integer; up:boolean; begin read(n); i:=n;j:=1;a[n,1]:=1;up:=true; for k:=( A )do begin if( B ) then begin i:=i-1;j:=j-1;end else begin i:=i+1;j:=j-1;end; if( C ) then begin i:=i+1;j:=j+2;up:=not up end; if( D ) then begin i:=i-2;j:=j-1;up:=not up end; if( E )then begin i:=i-1;up:=not up end; if( F )then begin j:=j+1;up:=not up end; a[i,j]:=k end; for i:=1 to n do begin writeln; for j:=1 to n do write(a[i,j]:3) end end. A_______________________ B_______________________ C_______________________ D_______________________ E_______________________ F_______________________ [程序] program prg2; type link=^node; node=record c:integer;next:link end; var p,pod,pev,q,tod,tev:link;n:integer; begin read(n);p:=nil; while n<>0 do begin new(q);q^.c:=n;q^.next:=p; p:=q;read(n) end; writeln;write(’Input link’);q:=p; while q<>nil do begin write(q^.c:4);q:=q^.next end; pod:=nil;( A ); while p<>nil do begin q:=p;( B );q^.next:=nil; if odd(q^.c) then begin if pod=nil then pod:=q else( C ) tod:=q end else begin if( D ) then pev:=q else( E ); ( F )end end; writeln;write(’Odd link’);q:=pod; while q<>nil do begin write(q^.c:4);q:=q^.next end; writeln;write(’Even link:’);q:=pev; while q<>nil do begin write(q^.c:4);q:=q^.next end end. A_______________________ B_______________________ C_______________________ D_______________________ E_______________________ F_______________________ |
|
我要投稿 新闻来源: 编辑: 作者: |
|
相关新闻 |
|
|
|
|
|