虚幻彼方 大结局:pascal 的一些题目

来源:百度文库 编辑:中科新闻网 时间:2024/05/03 06:43:28
帮帮解决下一下几个题 用pascal编写! 解决后有重赏!!!

1 输入x,y 输出最大公约数

2 输入一个二进制数 输出十进制数表示

3 求1~100之间所有偶数的和(包括100)

4 输入15个数 统计其中正、负、0的个数

帮帮忙啦~~~拜托啦!! 急等!!!!!!
最好详细些 有注释最好

1.
var
a,x,y:longint;
begin
read(x,y);
if x>y
then a:=y+1
else a:=x+1;
repeat{一个一个试,简单,易懂}
a:=a-1;
until (x mod a=0)and(y mod a=0);
writeln(a);
end.
2.
var
t,l,i,temp:integer;st:string;
begin
readln(st);
t:=0;l:=length(st);
for i:=l downto 1 do
if st[i]='1' then begin
temp:=1;
for j:=1 to l-i do temp:=temp*2;
inc(t,temp);
end;
writeln(total);
end.
3.
var
h,i:integer;
begin
h:=0;
for i:=1 to 100 do
if i mod 2=0{判断I是否为偶数,如果是就加在和上}
then h:=h+i;
writeln(h);
end.
4.
var
a:array[1..15]of integer;{一个数组,存放15个数}
i,z,f,l:integer;{Z是正数个数,F是负数个数,L是0的个数}
begin
z:=0;
f:=0;
l:=0;
for i:=1 to 15 do
read(a[i]);
for i:=1 to 15 do
if a[i]>0
then z:=z+1
else if a[i]<0
then f:=f+1
else l:=l+1;
writeln(z:10,f:10,l:10);
end.

1.
var a,b,c,d,e:integer;
begin
readln(a,b);
if a<>b then
begin
if a<b then begin d:=a;a:=b;b:=d;end;//保证a>b
c:=a mod b;
while c<>0 do//辗转相除
begin
a:=b;b:=c;
c:=a mod b;
end;
e:=b;
writeln('e=',e);
end else writeln('e=',1);
end.
原理:如果两个数有最大公约数A,那么这两个数,以及这两个数的差,还有大数除以小数的余数,必然都是A的倍数。
所以当最后两个数刚好能整除时,较小的数就是最大公约数。
2.
var total,l,i,temp:integer;st:string;
begin
readln(st);
total:=0;l:=length(st);
for i:=l downto 1 do
if st[i]='1' then begin
temp:=1;
for j:=1 to l-i do temp:=temp*2;
inc(total,temp);
end;
writeln(total);
end.
3.
var total,i:integer;
begin
total:=0;
for i:=1 to 50 do inc(total,i);
writeln(total*2);
end.//1到100的偶数就是2 4 6... 分别是1 2 3...的2倍
//所以直接由1加到50就可以了
4.var zs,fs,lin,i:byte;c:integer;
zs:=0;fs:=0;lin:=0;
for i:=1 to 15 do begin
read(c);
if c>0 then inc(zs) else
if c<0 then inc(fs) else
inc(lin);
end;
writeln('Total num above 0:',zs);
writeln('Total num below 0:',fs);
writlen('Total num equal to 0:',lin);
end.

1.
var a,b,c,d,e:integer;
begin
readln(a,b);
if a<>b then
begin
if a<b then begin d:=a;a:=b;b:=d;end;//保证a>b
c:=a mod b;
while c<>0 do//辗转相除
begin
a:=b;b:=c;
c:=a mod b;
end;
e:=b;
writeln('e=',e);
end else writeln('e=',1);
end.
原理:如果两个数有最大公约数A,那么这两个数,以及这两个数的差,还有大数除以小数的余数,必然都是A的倍数。
所以当最后两个数刚好能整除时,较小的数就是最大公约数。
2.
var total,l,i,temp:integer;st:string;
begin
readln(st);
total:=0;l:=length(st);
for i:=l downto 1 do
if st[i]='1' then begin
temp:=1;
for j:=1 to l-i do temp:=temp*2;
inc(total,temp);
end;
writeln(total);
end.
3.
var total,i:integer;
begin
total:=0;
for i:=1 to 50 do inc(total,i);
writeln(total*2);
end.//1到100的偶数就是2 4 6... 分别是1 2 3...的2倍
//所以直接由1加到50就可以了
4.var zs,fs,lin,i:byte;c:integer;
zs:=0;fs:=0;lin:=0;
for i:=1 to 15 do begin
read(c);
if c>0 then inc(zs) else
if c<0 then inc(fs) else
inc(lin);
end;
writeln('Total num above 0:',zs);
writeln('Total num below 0:',fs);
writlen('Total num equal to 0:',lin);
end.

ar a,b,c,d,e:integer;
begin
readln(a,b);
if a<>b then
begin
if a<b then begin d:=a;a:=b;b:=d;end;//保证a>b
c:=a mod b;
while c<>0 do//辗转相除
begin
a:=b;b:=c;
c:=a mod b;
end;
e:=b;
writeln('e=',e);
end else writeln('e=',1);
end.
2.
var total,l,i,temp:integer;st:string;
begin
readln(st);
total:=0;l:=length(st);
for i:=l downto 1 do
if st[i]='1' then begin
temp:=1;
for j:=1 to l-i do temp:=temp*2;
inc(total,temp);
end;
writeln(total);
end.
3.
var total,i:integer;
begin
total:=0;
for i:=1 to 50 do inc(total,i);
writeln(total*2);
end
4.var zs,fs,lin,i:byte;c:integer;
zs:=0;fs:=0;lin:=0;
for i:=1 to 15 do begin
read(c);
if c>0 then inc(zs) else
if c<0 then inc(fs) else
inc(lin);
end;
writeln('Total num above 0:',zs);
writeln('Total num below 0:',fs);
writlen('Total num equal to 0:',lin);
end.

1.
var a,b,c,d,e:integer;
begin
readln(a,b);
if a<>b then
begin
if a<b then begin d:=a;a:=b;b:=d;end
c:=a mod b;
while c<>0 do
begin
a:=b;b:=c;
c:=a mod b;
end;
e:=b;
writeln('e=',e);
end else writeln('e=',1);
end.
2.
var total,l,i,temp:integer;st:string;
begin
readln(st);
total:=0;l:=length(st);
for i:=l downto 1 do
if st[i]='1' then begin
temp:=1;
for j:=1 to l-i do temp:=temp*2;
inc(total,temp);
end;
writeln(total);
end.
3.
var total,i:integer;
begin
total:=0;
for i:=1 to 50 do inc(total,i);
writeln(total*2);
end
4.var zs,fs,lin,i:byte;c:integer;
zs:=0;fs:=0;lin:=0;
for i:=1 to 15 do begin
read(c);
if c>0 then inc(zs) else
if c<0 then inc(fs) else
inc(lin);
end;
writeln('Total num above 0:',zs);
writeln('Total num below 0:',fs);
writlen('Total num equal to 0:',lin);
end.

1:
Label 1;
Var
a,b,c,d,e:Longint;
Begin
Read(a);
Read(b);
If a<b Then
d:=a
Else
d:=b;
For c:=d Donwto 1 Do
If a Mod c = 0 Then
If b Mod c = 0 Then
Begin
Writeln(c);
Goto 1;
End;
1:
Wrteln;
End.

2:
Const
a=2;
Var
ch:Char;
b,c,d:Longint;
Begin
Read(ch);
While (ch in ['0'..'9']) Do
Begin
If (ch in ['0'..'9']) Then
b:=Ord(ch)-Ord('0');
c:=c*a+b;
Read(ch);
End;
Writeln(c);
End.

3:
Var
a,b:Longint;
Begin
For a:=1 To 100 Do
If a Mod 2 = 0 Then
b:=b+a;
Writeln(b);
End.