pascal语言:输入n个数,并输出最大的数和最小的数
发布网友
发布时间:2024-10-12 01:29
我来回答
共5个回答
热心网友
时间:2024-11-16 18:26
var
i,n,m,max,min:longint;
begin
readln(n);
max:=-maxlongint;
min:=maxlonint;//初始化
for i:=1 to n do
begin
readln(m);//输入一个数,循环n次
if m>max then max:=m;
if m<min then min:=m;//比较,更新最大最小值
end;
writeln(max)//最大;
writeln(min);//最小
end.
满意望采纳谢谢!
热心网友
时间:2024-11-16 18:25
var i,n,t,a,b:longint;
begin
readln(n);
readln(a);
readln(b);
if a<b then begin t:=a; a:=b; b:=t; end;
for i:=1 to n-2 do
begin
readln(t);
if t>a then a:=t;
if t<b then b:=t;
end;
writeln(a,' ',b);
end.
热心网友
时间:2024-11-16 18:23
var
i,n,max,min:integer;
a:array[1..100]of integer;
begin
readln(n);//输入n
max:=-maxint+1;//初始化
min:=maxint;//初始化
for i:=1 to n do
begin
read(a[i]);//读入每个数
if a[i]>max then max:=a[i];//如果这个数大于max,则把值赋给max
if a[i]<min then min:=a[i];//如果这个数小于min,则把值赋给min
end;
writeln(max,' ',min);//输出
end.
望采纳!!
热心网友
时间:2024-11-16 18:22
var n,i,tmp,max,min:longint;
begin
readln(n);
max:=-maxlongint;
min:=maxlongint;
for i:=1 to n do
begin
readln(tmp);
if tmp>max then max:=tmp;
if tmp<min then min:=tmp;
end;
writeln(max,min);
end.
热心网友
时间:2024-11-16 18:21
program tt;
var
i,n,m,max,min:longint;
begin
write('Please enter the N number limit:');
readln(n);
max:=-maxlongint;
min:=maxlongint;
for i:=1 to n do
begin
write('Please enter the ',i,' number');
readln(m);
if m> max then max:=m;
if m<min then min:=m
end;
writeln('The max number:',max);
writeln('The min number:',min);
readln;
end.