以下代码是program Production5;
var machine: array of char;
var machineindex: integer;
var product: array of integer;
var quality: array of integer;
var min, number: integer;
var i, j, extra: integer;
var myTable: array[1..7,1..10,1..2] of integer;
begin
i:= 0;
j:= 0;
number := 0;
min := 5;
extra := 5;
SETLENGTH( machine, min );
SETLENGTH( product, min );
SETLENGTH( quality, min );
writeln('Input Machine ID ( A, B, C, D, E, F or G ) ');
readln(machine[number] );
while (machine[number] <> '*') do
begin
while ( ORD( machine[number] ) < 65 ) or ( ORD( machine[number] ) > 71 ) do
begin
writeln('Input Invalid. Please try again.');
readln(machine[number] );
end;
machineindex := (ORD(machine[number])-65);
writeln('Input Product Number ( 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9 ) ');
readln(product[number] );
while ( product[number] < 0 ) or ( product[number] > 9 ) do
begin
writeln('Input Invalid. Please try again.');
readln(product[number] );
end;
writeln('Quality Control Check. Input 0 for GOOD or 1 for BAD.');
readln(quality[number] );
while ( quality[number] <> 0 ) and ( quality[number] <> 1 ) do
begin
writeln('Input Invalid. Please try again.');
readln(quality[number] );
end;
myTable[machineindex,(product[number]),(quality[number])] := myTable[machineindex,(product[number]),(quality[number])] + 1;
number := number + 1;
if number = LENGTH(machine) then
begin
SETLENGTH(machine, LENGTH(machine)+extra);
SETLENGTH(product, LENGTH(product)+extra);
SETLENGTH(quality, LENGTH(quality)+extra)
end;
writeln('Input Machine ID ( A, B, C, D, E, F or G ) ');
readln(machine[number] );
end;
writeln(' 0 1 2 3 4 5 6 7 8 9');
for i := 0 to 6 do
begin
write(CHR(65+i),' ');
for j := 0 to 9 do
begin
write(myTable[i,j,0], ' ');
end;
writeln('');
end;
writeln();
writeln(' 0 1 2 3 4 5 6 7 8 9');
for i := 0 to 6 do
begin
write(CHR(65+i),' ');
for j := 0 to 9 do
begin
write(myTable[i,j,1], ' ');
end;
writeln('');
end;
writeln('');
writeln('');
writeln('EXIT');
readln;
end.
条件语句的基本实现 -
if - else
答案 0 :(得分:4)
6.9.2外部对象定义
<强>语义强>
1 如果对象的标识符声明具有文件范围和初始化程序,则 声明是标识符的外部定义。
2 具有没有初始化程序的文件范围的对象的标识符声明 没有存储类说明符或存储类说明符静态,构成一个 暂定的定义。如果翻译单元包含一个或多个临时定义 然后,标识符和转换单元不包含该标识符的外部定义 行为就像翻译单元包含该文件范围声明一样 标识符,具有复制类型,如翻译单元的末尾,带有初始化程序 等于0。
因此,全局变量永远不会被初始化,它们总是被初始化为0
。因此输出how r u
。
答案 1 :(得分:1)
//全球 int x;
您已将'x'声明为全局变量...因此它的默认值为0。