function MaxFirstDigit(n: Integer): Integer; var maxDigit, firstDigit: Integer; begin maxDigit := 0; while n <> 0 do begin firstDigit := n mod 10; if firstDigit > maxDigit then maxDigit := firstDigit; n := n div 10; end; MaxFirstDigit := maxDigit; end;
var num, maxFirst: Integer; begin maxFirst := 0; repeat Write('Enter a number (0 to exit): '); ReadLn(num); if num <> 0 then begin if MaxFirstDigit(num) > maxFirst then maxFirst := MaxFirstDigit(num); end; until num = 0; WriteLn('The maximum first digit is: ', maxFirst); end.
program MaxFirstDigit;
function MaxFirstDigit(n: Integer): Integer;
var
maxDigit, firstDigit: Integer;
begin
maxDigit := 0;
while n <> 0 do
begin
firstDigit := n mod 10;
if firstDigit > maxDigit then
maxDigit := firstDigit;
n := n div 10;
end;
MaxFirstDigit := maxDigit;
end;
var
num, maxFirst: Integer;
begin
maxFirst := 0;
repeat
Write('Enter a number (0 to exit): ');
ReadLn(num);
if num <> 0 then
begin
if MaxFirstDigit(num) > maxFirst then
maxFirst := MaxFirstDigit(num);
end;
until num = 0;
WriteLn('The maximum first digit is: ', maxFirst);
end.