主题:求救啊!定加分1
我是新手tc
[专家分:0] 发布于 2005-11-29 23:25:00
题目:读入10个数,输出偶数项及它们的和,输出奇数项及它们的平均数.
用PASCAL语言!
回复列表 (共4个回复)
沙发
onasp [专家分:5600] 发布于 2005-11-30 08:48:00
program Project1;
{$APPTYPE CONSOLE}
var
i:byte;
S1,S2: real;
N : array[1..10] of real;
begin
S1:=0;
for i:=1 to 10 do
begin
readln(N[i]);
if i mod 2 =1 then
S1 := S1+(N[i]/5)
else
S2 := S2+N[i];
end;
for i:=1 to 10 do
if i mod 2 =1 then
write(N[i]:6:2);
writeln(S1:10:2);
for i:=1 to 10 do
if i mod 2 = 0 then
write(N[i]:6:2);
writeln(S2:10:2);
readln;
end.
板凳
lmj9201 [专家分:1400] 发布于 2005-11-30 13:46:00
var
a:array[1..10]of real;
i:integer;
s1,s2:real;
begin
for i:=1 to 10 do read(a[i]);
for i:=1 to 10 do
if i mod 2=0 then
s1:=s1+a[i]
else
s2:=s2+a[i];
s2:=s2/5;
write(s1:0:5,s2:10:5);
end.
3 楼
xuzhenyi [专家分:850] 发布于 2005-12-06 21:33:00
{$N+}
const
max=10;
var
i,n:integer;
ave:extended;
tot:longint;
a:array[1..max] of longint;
begin
for i:=1 to max do
read(a[i]);
for i:=1 to max div 2 do begin
write(a[i*2],' ');
tot:=tot+a[i*2];
end;
writeln;
writeln(tot);
readln;
tot:=0;
for i:=1 to max div 2 do begin
write(a[i*2-1],' ');
tot:=tot+a[i*2-1];
end;
ave:=tot/(max div 2);
writeln;
writeln(ave:1:1);
readln;
end.
4 楼
编程黑客 [专家分:1660] 发布于 2006-01-01 22:37:00
var
a:array[1..10]of real;
i:integer;
s1,s2:real;
begin
for i:=1 to 10 do read(a[i]);
for i:=1 to 10 do
if i mod 2=0 then
s1:=s1+a[i]
else
s2:=s2+a[i];
s2:=s2/5;
write(s1:0:5,s2:10:5);
end.
我来回复