麻烦大家帮我做几道题,学过pascal的进。。。急~~!!!

2024-12-27 16:25:15
推荐回答(5个)
回答1:

1、a、b、c 分别等于1、12、123 把它们按向左对齐、向右对齐的方式打印出来;

program zuo_you_duiqi;
var i,p:integer;
begin
for i:=1 to 3 do begin
for p:=1 to i do
write (p);
writeln;
end;
writeln ('*****');
for i:=1 to 3 do begin
write (1:4-i);
for p:=2 to i do
write (p:2);
writeln;
end;
writeln ('*****');
for i:=1 to 3 do begin
write (1:4-i);
for p:=2 to i do
write(p);
writeln;
end;
readln;readln;
end.

2、输入一个四位整数,把它们的各位数字倒序输出。(提示:用MOD和DIV);
program daoxu_shuchu;
uses crt;
var a:longint;
procedure print(c:longint);
begin
if c>99 then begin
write (c mod 10);
print (c div 10);
end else begin
write (c mod 10);
write (c div 10);
end;
end;
begin
Readln(a);
print (a);
readkey
end.

3、从键盘上读入小写的pascal,利用CHR和ORD函数输出大写的PASCAL;

program Noname10;
uses crt;
var c:packed array[1..10]of char;p:integer;
begin
read (c);
p:=1;
while ord(c[p])<> 0 do
begin
write(chr(ord (c[p])-32));
inc(p);
end;
readkey;
end.

4、从键盘读入一个实数,利用Round和Trunc函数输出该实数本身的整数部
分、小数部分和四舍五入的值;

program shixu_fenjie;
uses crt;
var a:real;
begin
Readln(a);
writeln;
writeln (a);
writeln (trunc(a));
writeln (a-trunc(a));
writeln (round(a));
readkey
end.

5、输入三个数,将其按照从小到大输出;
用了随即函数

有3种

冒泡排序
procedure maopaopaixu;
const n=3;
var a:array[1..n] of integer;
i,t:integer;
f:boolean;
begin
randomize;
for i:=1 to n do a[i]:=random(90)+10;
for i:=1 to n do write(a[i]:4);
writeln;writeln; for i:=1 to n do write('↓':4);writeln;
repeat
f:=true;
for i:=1 to n-1 do
if a[i]> a[i+1] then begin
t:=a[i]; a[i]:=a[i+1]; a[i+1]:=t;
f:=false;
end;
until f;
for i:=1 to n do writeln(a[i]:4);
readln;
readln;
end.

选择排序

program xuanzepaixu;
const n=3;
var a:array[1..n] of integer;
i,j,p:integer;
begin
randomize;
for i:=1 to n do a[i]:=random(90)+10;
for i:=1 to n do write(a[i]:4);
writeln;writeln; for i:=1 to n do write('↓':4);writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i] > a[j] then
begin
p:=a[i];
a[i]:=a[j];
a[j]:=p;
end;
for i:=1 to n do
write(a[i]:4); writeln;
readln;readln;readln;
end.

希尔排序

program xier_paixu;
const n=3;
var
a:array[1..3] of integer;
i,j,bc:integer;
f:boolean;
begin
randomize;
for i:=1 to n do a[i]:=random(90)+10;
for i:=1 to n do write(a[i]:4);
writeln;writeln; for i:=1 to n do write('↓':4);writeln;
writeln;writeln; for i:=1 to n do write('↓':4);writeln;
bc:=n;
while bc>1 do begin
bc:= bc div 2;
repeat
f:=true;
for i:=1 to n-bc do
if a[i]> a[i+bc] then begin
j:=a[i]; a[i+bc]:=a[i]; a[i+bc]:=a[i];
end;
until f=false;
for i:=1 to n do writeln(a[i]:4);
readln;readln;readln;
end.
6、任意输入三个数,判断是否能构成三角形,如能,则求出其面积,不能,则打印“NO”。要构成三角形,必须满足两边之和大于第三边,即:B+C>A 或A+C>B 或A+B>C,如满足,则用海伦公式计算;

var k,l,a,b,c:integer;
f:boolean;
begin
f:=false;
while not f do begin
readln(a,b,c);
if f= (a + b > c) and (a + c > b) and (b + c >a) then
writeln('yes') else writeln('no');
end;
readln;
readln;
readln;
end.
7、打印某年某月有几天。

program nianyueri;
var
year,month:integer;
begin
readln(year,month);
if month=2 then
begin
if (year mod 400=0) or ((year mod 100<>0) and (y mod 4=0) then writeln('29') else writeln('28');
end;
case month of
1,3,5,7,8,10,12:writeln('31');
4,6,9,11:writeln('30');
end;
end.

给点分,全自己 OK滴(除了7 ,直接&&)
*_* @_~

回答2:

5.
program yx1;
var a,b,c,t:integer;
begin
write('input integer a,b,c:');
readln(a,b,c);
if abegin
t:=a; a:=b; b:=t
end;
if abegin
t:=a; a:=c; c:=t
end;
if bbegin
t:=b; b:=c; c:=t
end;
writeln(a, ' ',b,' ',c)
end.

回答3:

前四题见http://zhidao.baidu.com/question/33734474.html
No.5
program l_5(input,output);
var
a,b,c,temp:integer;
begin
readln(a,b,c);
if a>b then
begin
temp:=a;
a:=b;
b:=temp;
end;
if b>c then
begin
temp:=b;
b:=c;
c:=temp;
end;
if a>b then
begin
temp:=a;
a:=b;
b:=temp;
end;
writeln(a,' ',b,' ',c);
end.

No.6
program l_6(input,output);
var
l:real;
a,b,c:integer;
begin
readln(a,b,c);
if (b+c>a) and (a+c>b) and (a+b>c) then
begin
l:=(a+b+c)/2;
writeln(sqrt(l*(l-a)*(l-b)*(l-c)):0:0);
end
else
writeln('NO');
end.

No.7
program l_7(input,output);
var
year,month:integer;
begin
readln(year,month);
if month=2 then
begin
if (year mod 400=0) or ((year mod 100<>0) and (y mod 4=0) then writeln('29') else writeln('28');
end;
case month of
1,3,5,7,8,10,12:writeln('31');
4,6,9,11:writeln('30');
end;
end.

参考资料里的是关于海伦公式的简介

回答4:

7.
var y:integer;
m:1..12;
begin
readln(y,m);
case m of
1,3,5,7,8,10,12:writeln(31);
4,6,9,11:writeln(30);
2:if ((y mod 4=0)and(y mod 100<>0))or((y mod 400=0)and(y mod 100=0))then writeln(29) else writeln(28);
end;{case}
end.

回答5:

5.
program
yx1;
var
a,b,c,t:integer;
begin
write('input
integer
a,b,c:');
readln(a,b,c);
if
athen
begin
t:=a;
a:=b;
b:=t
end;
if
athen
begin
t:=a;
a:=c;
c:=t
end;
if
bthen
begin
t:=b;
b:=c;
c:=t
end;
writeln(a,
'
',b,'
',c)
end.