用PASCAL编程

2024-11-22 08:14:10
推荐回答(5个)
回答1:

var
a,b:array[1..10] of longint;
ta,tb,sum,i,j:longint;
avg:real;
begin
ta:=0;tb:=0;sum:=0;avg:=0;
for i:=1 to 10 do begin
read(j);
if odd(j) then begin
sum:=sum+j;
inc(ta);a[ta]:=j;
end
else begin
avg:=avg+j;
inc(tb);b[tb]:=j;
end;
for i:=1 to ta do write(a[i],' ');
writeln;writeln(sum);
for i:=1 to tb do write(b[i],' ');
writeln;
if tb>0 then writeln(avg/tb:0:4)
else =writeln(0);
end.

怎么觉得有点复杂??

回答2:

var
i,m1,m2,k:longint;
a:array[1..10] of longint;
begin
for i:=1 to 10 do
readln(a[i]);
for i:=1 to 10 do
if a[i] mod 2<>0 then
begin
write(a[i],' ');
m1:=m1+a[i];
end;
writeln;
writeln(m1);
for i:=1 to 10 do
if a[i] mod 2=0 then
begin
write(a[i],' ');
m2:=m2+a[i];
inc(k);
end;
writeln;
if k<>0 then
writeln(m2/k) else writeln(0);
end.

回答3:

var
a:array[1..10]of integer;
i,s:longint;
begin
for i:=1 to 10 do read(a[i]);
for i:=1 to 10 do
if odd(a[i]) then write(a[i],' ');
writeln;
s:=0;
for i:=1 to 10 do
if odd(a[i]) then s:=s+a[i];
writeln(s);
for i:=1 to 10 do
if not odd(a[i]) then write(a[i],' ');
writeln;
s:=0;
for i:=1 to 10 do
if not odd(a[i])then s:=s+a[i];
writeln(s/10:0:1);
end.

回答4:

var
a:array[1..10]of integer;
i,s:longint;
begin
for i:=1 to 10 do read(a[i]);
for i:=1 to 10 do
if odd(a[i]) then write(a[i],' ');
writeln;
s:=0;
for i:=1 to 10 do
if odd(a[i]) then s:=s+a[i];
writeln(s);
for i:=1 to 10 do
if not odd(a[i]) then write(a[i],' ');
writeln;
s:=0;
for i:=1 to 10 do
if not odd(a[i])then s:=s+a[i];
writeln(s/10:0:1);
end.

回答5:

var
a,b:array[1..10] of longint;
ta,tb,sum,i,j:longint;
avg:real;
begin
ta:=0;tb:=0;sum:=0;avg:=0;
for i:=1 to 10 do begin
read(j);
if odd(j) then begin
sum:=sum+j;
inc(ta);a[ta]:=j;
end
else begin
avg:=avg+j;
inc(tb);b[tb]:=j;
end;
for i:=1 to ta do write(a[i],' ');
writeln;writeln(sum);
for i:=1 to tb do write(b[i],' ');
writeln;
if tb>0 then writeln(avg/tb:0:4)
else =writeln(0);
end.