我问大家一道题,是pascal的,十万火急!要快!!!

来源:百度知道 编辑:UC知道 时间:2024/05/16 17:26:48
编写一程序,验证角谷猜想,所谓的角谷猜想就是:“对于任意大于1的自然数n,若n为奇数,将n变为3*n=1;若n为偶数则将n变为n的一半,经过若干次这样的变换,一定会使n变为1”,如:
6——6/2=3——3*3+1=10——10*10/2=5——5*3+1=16——16/2=8——8/2=4——4/2=2——2/2=1

Var
n:integer;
Begin
readln(n);
if n>1 then
repeat
if odd(n)
then n:=3*n+1
else n:=n div 2;
until n=1;
if n=1 then writeln('true');
readln;
End.

Program ex;
Var x:integer;yes:boolean;
Begin
readln(x);
yes:=false;
if x>1 then
repeat
if x mod 2 = 1 then x:=3*x+1
else x:=x div 2;
until x=1;
if x=1 then yes:=true;
if yes then writeln('yes');
readln;
End.
不论输入哪个数,最后输出结果都是yes.