Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
program Hailstone_number;
var
i,n,x:integer;
begin
i:=0;
write('Input a number?');
readln(n);
writeln('Initial value is ',n);
while n<>1 do
begin
if n mod 2 = 0 then
n:= n div 2
else
n:= 3*n+1;
writeln('Next value is ',n);
i:=i+1;
end;
writeln;
writeln('Final value is 1');
writeln('Number of steps is ',i);
end.
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more