考试科目:程序设计
专业:产业经济
一,计算类(40分)
阅读下列程序,将程序运行结果写在答卷相应栏内.(如果有数据,请见答卷相应题处,即7
,8题)
1,program call:
type te=(a,b,c,d);
var I,j,n,sum:integer;
ch;char;e:te;
begin
sum:0;
writeln;
read(ch);
case ch of
"A":begin read(n);
while n<0 do
begin
sum:=sum+n;
read(n)
end
end;
"B":
repeat
read(n);
sum:=sum+n;
until n>0;
"c":
for I:=11 to 14
do
begin
read(n);
sum:=sum+n
end;
"D":
for e:=a to d do
sum:=sum+ord(e);
end;
write(ch,'sum=',sum:2)
end.
输入请见答案.
2,program call2:
var n:integer;
function sum(n:integer):interger
var s:integer;
begin
s:=0;
while n>0
do
begin
s:=s+n mod 10;
n:=n div 10;
end;
sum:=s;
end;
begin
writeln;
for n:=20 to 29 do
if n mod sum(n)=0
then write(n:3);
end;
3.program cal3
var a,b:char;
procedure p(var a:char;b:char);
begin
a:=char(ord(a)+ord(b))div 2);
b:=chr(ord(b)+3);
write(a,b);
end;
begin writeln;
a:='A';
b:='M';
p(a,b);
writeln(a,b);
p(b,a);
writeln(a,b);
p(a,'E');
writeln(a,b);
end;
4,program cal 4;
function f(a,b:integer):integer;
begin
if a<=b
then
f:=(a+b)div 2;
else f:=f((a+b)div 2,b+1);
end;
begin writeln;
write(f(10,3):3,f(20,f(10,3)):3);
write(f(f(20,10),f(10,3)):3);
end;
5,
program cal 5;
type arr=array[1..11,1..11]of integer;
var a:arr; i,j,k,n:integer;
begin
n:=5;
for i:=1 to n do
for j:=1 to n do a[i,j]:=0;
i:1;
j:=(n+1)div 2;
a[i,j]:=1;
for k:=2 to n*n do
begin
if (i=1)and (j=n)
then i:=i+1;
else
begin
i:=n-(n-i+1)mod n;
j:=j mod n +1;
if a[i,j]<>=0;
then
begin
i:=i+2;
] j:=j-1;
end;
end;
if 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;
6,
program cal 6
type tst=set of boolean;
procedure pnts(s:tst);
var b:boolean;
begin writeln;write('[');
for b:=false to true do
if b in s
then write(b:6);
write(']');
end;
begin s1:=[];s2=[];
for i:=1 to 3 do
begin
s1:=s1+[2*i+1<3*i-2];
s2:=s2+[2*i+1=s*i-1];
end;
pnts(s1); pnts(s2);
pnts(s1-s2);
pnts(s1*s2);
end
二,编程题(60分)阅读下列程序,填空.
7, program prg1;
var n:inerger ;
function f( ):interger;
var u:integer;
begin ( );
while ( )do
begin u:=u*10+n mod 10;
n:=n div 10;
end ;
( );
end;
begin n:=1000;
repeat
n:=n+1;
until 4*n =f(n);
writeln('n=',n:4)
end;
[说明]:该程序寻找自然数n,将n的各位数码倒置后的新数是原数的4倍
8.program prg2;
type arr=array[1..20,1..5]of char;
var a:arr;s:string;
i,j,n:integerr;
begin read(s);
i:=1;
( );
while s[i]<>'.'do
begin
if s[i] in ( );
then
begin n:=n+1;j:=0;
while( )do
begin j:=j+1;
if( )
then a[n,j]:=chr(ord(s[i]+32);
else a[n,j]:=s[i];
i:=i+1;
end;
while j<5 do
begin j:=j+1;
a[n,j]=''
end;
end;
else ( );
end;
for i:=1 to n do
begin
writeln;
for j:=1 to 5
do
write(d[i,j]);
end;
end;
[说明]该程序输入一个句子(字符窜),将句子中每个单词存入数组a,每个单词占a的一行
并且:
1,大写改小写
2,不足5个字母的,后面补以空格.
3,超过5个字母的,后面字母掠去。