用FREE PASCAL 编写 ] 1、任意输入3个数,输出中间的数。
2、计算1-1/3+1/5-1/7+……前20项的值。3、计算数列1,2,4,7,11,……前20项的值。4、随意输入若干个小于10的正整数,直到输入10为止。统计共输入...
2、计算1-1/3+1/5-1/7+……前20项的值。
3、计算数列1,2,4,7,11,……前20项的值。
4、随意输入若干个小于10的正整数,直到输入10为止。统计共输入了多少个数,其中有多少个偶数,这些偶数的和是多少?
5、将第4题的停止输入标志“10”改为“#”,又该如何统计?(提示:利用ASCII,用函数ord()将字符转化为数字后再计算。) 展开
3、计算数列1,2,4,7,11,……前20项的值。
4、随意输入若干个小于10的正整数,直到输入10为止。统计共输入了多少个数,其中有多少个偶数,这些偶数的和是多少?
5、将第4题的停止输入标志“10”改为“#”,又该如何统计?(提示:利用ASCII,用函数ord()将字符转化为数字后再计算。) 展开
4个回答
展开全部
1、var a:array[1..3]of longint;
i,j,t:longint;
begin
for i:=1 to 3 do read(a[i]);
for i:=1 to 2 do
for j:=2 to 3 do
if a[i]>a[j] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
writeln(a[2]);
end.
2、var s:real;
i,t,k:longint;
begin
i:=1;s:=0;t:=1;
for k:=1 to 20 do
begin
s:=i*(1/t);
inc(t,2);
i:=-i;
end;
writeln(s:0:10);
end.
3、var t,i:longint;
begin
t:=1;
for i:=1 to 20 do
begin
write(t,',');
t:=t+i
end;
writeln(t);
end.
4、var n,i,s:longint;
begin
read(n);
i:=1;
if not(odd(n)) then s:=n;
while n<10 do
begin
read(n);
i:=i+1;
if not(odd(n)) then s:=s+n;
end;
writeln(i);
writeln(s);
end.
5、var n,i,s:longint;c:char;
begin
read(c);n:=ord(c);
i:=1;
if not(odd(n)) then s:=n;
while n<10 do
begin
read(c);n:=ord(c);
i:=i+1;
if not(odd(n)) then s:=s+n;
end;
writeln(i);
writeln(s);
end.
i,j,t:longint;
begin
for i:=1 to 3 do read(a[i]);
for i:=1 to 2 do
for j:=2 to 3 do
if a[i]>a[j] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
writeln(a[2]);
end.
2、var s:real;
i,t,k:longint;
begin
i:=1;s:=0;t:=1;
for k:=1 to 20 do
begin
s:=i*(1/t);
inc(t,2);
i:=-i;
end;
writeln(s:0:10);
end.
3、var t,i:longint;
begin
t:=1;
for i:=1 to 20 do
begin
write(t,',');
t:=t+i
end;
writeln(t);
end.
4、var n,i,s:longint;
begin
read(n);
i:=1;
if not(odd(n)) then s:=n;
while n<10 do
begin
read(n);
i:=i+1;
if not(odd(n)) then s:=s+n;
end;
writeln(i);
writeln(s);
end.
5、var n,i,s:longint;c:char;
begin
read(c);n:=ord(c);
i:=1;
if not(odd(n)) then s:=n;
while n<10 do
begin
read(c);n:=ord(c);
i:=i+1;
if not(odd(n)) then s:=s+n;
end;
writeln(i);
writeln(s);
end.
展开全部
(2)
const
n=20;
var
ans:real;
i,j:integer;
begin
ans:=0;
i:=1;
j:=0;
while j<n do
begin
inc(j);
if j mod 2=1 then ans:=ans+1/i else ans := ans-1/i;
i:=i+2;
end;
writeln(ans:0:5);//保留5位小数
readln;//这句~还是去掉吧,我用lazarus的 调试用
end.
(3)const
n=20;
var
a,b,i:integer;
begin
a:=1;
b:=1;
for i:= 1 to n do
begin
write(a,' ');
a:=a+b;
b:=b+1;
end;
readln;
end.
4var
x,sum,ans1,ans2:integer;
begin
read(x);
sum:=0;
ans1:=0;
ans2:=0;
while x<>10 do
begin
inc(ans1);
if x mod 2=0 then
begin
inc(ans2);
sum:=sum+x;
end;
read(x);
end;
writeln(ans1,' ',ans2,' ',sum) ;
readln;
readln;
end. (不包括10)
5:var
x:char;
ar:array[1..10] of integer;
n,i,ans,sum,a:integer;
begin
read(x);
n:=0;
while x<>'#' do
begin
while x=' ' do read(x);
if x='#' then break;
inc(n);
a:=0;
while x<>' ' do
begin
a:=a*10+ord(x)-48;
read(x);
end;
ar[n]:=a;
end;
for i:=1 to n do
begin
if ar[i] mod 2=0 then
begin
inc(ans);
sum:=sum+ar[i]
end;
end;
writeln(n,' ',ans,' ',sum);
readln;
readln;
end. (支持多位自然数)
const
n=20;
var
ans:real;
i,j:integer;
begin
ans:=0;
i:=1;
j:=0;
while j<n do
begin
inc(j);
if j mod 2=1 then ans:=ans+1/i else ans := ans-1/i;
i:=i+2;
end;
writeln(ans:0:5);//保留5位小数
readln;//这句~还是去掉吧,我用lazarus的 调试用
end.
(3)const
n=20;
var
a,b,i:integer;
begin
a:=1;
b:=1;
for i:= 1 to n do
begin
write(a,' ');
a:=a+b;
b:=b+1;
end;
readln;
end.
4var
x,sum,ans1,ans2:integer;
begin
read(x);
sum:=0;
ans1:=0;
ans2:=0;
while x<>10 do
begin
inc(ans1);
if x mod 2=0 then
begin
inc(ans2);
sum:=sum+x;
end;
read(x);
end;
writeln(ans1,' ',ans2,' ',sum) ;
readln;
readln;
end. (不包括10)
5:var
x:char;
ar:array[1..10] of integer;
n,i,ans,sum,a:integer;
begin
read(x);
n:=0;
while x<>'#' do
begin
while x=' ' do read(x);
if x='#' then break;
inc(n);
a:=0;
while x<>' ' do
begin
a:=a*10+ord(x)-48;
read(x);
end;
ar[n]:=a;
end;
for i:=1 to n do
begin
if ar[i] mod 2=0 then
begin
inc(ans);
sum:=sum+ar[i]
end;
end;
writeln(n,' ',ans,' ',sum);
readln;
readln;
end. (支持多位自然数)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1
var a:array [1..3] of integer;
i,j,m:integer;
begin
read(a[1],a[2],a[3]);
for i:=1 to 2 do
for j:=i+1 to 3 do
if a[i]>a[j] then begin m:=a[i];a[i]:=a[j];a[j]:=m; end;
write(a[2]);
end.
2
var b,i:real;
begin
b:=1;
for i:=1 to 20 do
b:=b-1/i;
write(b);
end.
3
var a,b:integer;
begin
write('1 2');
a:=2;
for b:=3 to 20 do
begin
a:=a+b;
write(a,' ');
end;
end.
4
var a,i,j:integer;
begin
while a<>10 do
begin
read(a);
i:=i+1;
if a mod 2 = 0 then j:=j+1;
end;
writeln(i);
writeln(j);
end.
5
var a,i,j:integer;
begin
while ord(a)<>ord('#') do
begin
read(a);
i:=i+1;
if a mod 2 = 0 then j:=j+1;
end;
writeln(i);
writeln(j);
end.
var a:array [1..3] of integer;
i,j,m:integer;
begin
read(a[1],a[2],a[3]);
for i:=1 to 2 do
for j:=i+1 to 3 do
if a[i]>a[j] then begin m:=a[i];a[i]:=a[j];a[j]:=m; end;
write(a[2]);
end.
2
var b,i:real;
begin
b:=1;
for i:=1 to 20 do
b:=b-1/i;
write(b);
end.
3
var a,b:integer;
begin
write('1 2');
a:=2;
for b:=3 to 20 do
begin
a:=a+b;
write(a,' ');
end;
end.
4
var a,i,j:integer;
begin
while a<>10 do
begin
read(a);
i:=i+1;
if a mod 2 = 0 then j:=j+1;
end;
writeln(i);
writeln(j);
end.
5
var a,i,j:integer;
begin
while ord(a)<>ord('#') do
begin
read(a);
i:=i+1;
if a mod 2 = 0 then j:=j+1;
end;
writeln(i);
writeln(j);
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这么基础的题就自己写,总看别人程序得不到提高
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询