pascal语言 编写一个程序

pascal语言 编写一个程序
pascal语言
1.编写一个程序,它读三个数据行,把第一行的第一个字符、第二行的第二个字符、第三行的第三个字符接连在一行上打印。 (例输入三行:a b cㄌ e f gㄌ d h kㄌ 输出:a f k)。

2.读一个在c和x之间的字母,打印出该字母位于中间的相邻五个字母。(例如输入字母G,输出EFGHI)

3.输入某年某月,输出该月的天数。

4.求100到999中水仙花数。(例三位数abc,若a3+b3+c3=abc则abc为水仙花数,例如153,13+53+33=153,则153为水仙花数)

5.输出1―999能被3整除,且至少有一位数字是5的所有整数。

6.在1―500中找出同时满足用3除余2,用5除余3,用7除余2的所有整数。
谢谢啦
1.思路:用一个字符串数组储存输入的数据,并分别输出。
程序:
Var
a:array[1..3]of string;
i:integer;
Begin
For i:=1 to 3 do
Readln(a[i]);
For i:=1 to 3 do
Write(a[i][i]);
End.
2.思路:读入数据,存入字符串变量a中,校验a的值是否符合要求,然后再将a的ascii码求出,输出相邻的五个。
程序:
Var
a:char;
i,j:integer;
Begin
Readln(a);
i:=ord(a); {求出a的ascii码值}
If ((i>66)and(i<89))or((i>98)and(i<121))then {验证a在大写和小写c和x的ascii码之间}
Begin
For j:=(i-2) to (i+2) do
Write(chr(j)); {根据ascii码求字符}
End
Else
Begin
Write('Input Error!');
Exit;
End;
Readln;
End.
3.先判断月份是否二月(二月是特殊的月,闰年有29天,余搏平年有28天),是就判断是否平年,是平年就输出28天,不是就输出29天,不是就判断月份是1,3,5,7,8,10,12这几个月,就输出31天,如果是4,6,9,11这几个月就输出30天。
程序:
Var
i,j:integer;
Begin
readln(j,i);
Case i of
1,3,5,7,8,10,12:write('31days');
4,6,9,11:write('30 days');
2:If (j mod 4=0) then write('29 days') else write('28 days');
End;
End.
4.水仙花数是指数a,b,c中,a的立方加b的立方加c的立方等于abc。可以用一个三维数组存入abc,历遍100至999,如果a*a*a+b*b*b+c*c*c=a,b,c则输出。
Var
a,b,c:integer;
Begin
For a:=1 to 9 do
For b:=0 to 9 do
For c:=0 to 9 do
If(a*a*a+b*b*b+c*c*c=a*100+b*10+c)then
Writeln(a,b,c);
Readln;
End.
5.用a,b,c分别代表个位,十位,百位历遍1-999,如果a*100+b*10+c mod 3=0【三位数abc除3的余数是皮毁搜零,代表被3整除】,和【and】a=5或【or】b=5或【or】c=5,就输出abc。
程序:
Var
a,b,c:integer;
n:boolean;
Begin
For a:=0 to 9 do
For b:=0 to 9 do
For c:=1 to 9 do
Begin
If (((a*100+b*10+c) mod 3=0) and ((a=5)or(b=5)or(c=5))) then
writeln(a,b,c);
End;
Readln;
End.
6.还是和5同样方法,判断部分略微修改就是了。
Var
a,b,c:integer;
n:boolean;
Begin
For a:=0 to 4 do
For b:=0 to 9 do
For c:=1 to 9 do
Begin
If (((a*100+b*10+c-2) mod 3=0) and (a*100+b*10+c-3) mod 5=0) and (a*100+b*10+c-2) mod 7=0)) then
writeln(a,b,c);
End;
Readln;
End.
打了好久那..手都酸燃历了,程序全都通过测试,合乎要求,完全原创,请求楼主采纳~
1、program ex1(input,output);
var
a,b,c:integer;
begin
readln(a);
readln(b);
readln(c);
write(a,' ',b,' ',c);
readln;
readln
end.
2、program ex2(input,output);
type
ex=array[1..5]of char;
var
a:ex;
i:integer;
begin
repeat
writeln('input a char in c and x');
readln(a[3]);
until (a[3]>='c')and(a[3];<='腊首x');
for i:=2 downto 1 do a[i]:=pred(a[i+1]);
for i:=4 to 5 do a[i]:=succ(a[i-1]);
for i:=1 to 5 do write(a[i],' ');
readln;
readln
end.
3、轮侍数program ex3(input,output);
var
year,month:integer;
begin
writeln('input the year and the month.'谈基);
readln(year,month);
write(year,'.',month,'1-');
case month of
2,4,6,9,11:write(30);
2:if (year mod 4=0)and(year mod 100<>0)or(year mod 400=0)then write(29) else write(28);
else write(31);
readln;
readln
end.
4、program ex4(input,output);
var
i,j,k:integer;
begin
for i:=1 to 9 do
for j:=0 to 9 do
for k:=0 to 9 do
if i*i*i+j*j*j+k*k*k=i*100+j*10+k then write(i*100+j*10+k,' ');
readln;
readln
end.
4、program ex4(input,output);
var
i,j,k:integer;
begin
for i:=0 to 9 do
for j:=0 to 9 do
for k:=1 to 9 do
if ((i=5)or(j=5)or(k=5))and((i*100+j*10+k)mod 3=0) then write(i*100+j*10+k);
readln;
readln
end.
5、program ex5(input,output);
var
i:integer;
begin
for i:=1 to 500 do if (i mod 3=2)and(i mod 5=3)and(i mod 7=2) then write(i,' ');
readln;
readln
end.
← 上一篇: 下一篇: →