write('Enter a four-digit number: '); readln(number);
if (number < 1000) or (number > 9999) then begin writeln('Please enter a valid four-digit number.'); end else begin digit := number mod 10; sum := sum + digit; number := number div 10;
digit := number mod 10; sum := sum + digit; number := number div 10; digit := number mod 10; sum := sum + digit; number := number div 10; digit := number mod 10; sum := sum + digit; writeln('Sum of digits: ', sum);
program SumOfDigits;
var
number, sum, digit: integer;
begin
sum := 0;
write('Enter a four-digit number: ');
readln(number);
if (number < 1000) or (number > 9999) then
digit := number mod 10;begin
writeln('Please enter a valid four-digit number.');
end
else
begin
digit := number mod 10;
sum := sum + digit;
number := number div 10;
sum := sum + digit;
number := number div 10;
digit := number mod 10;
sum := sum + digit;
number := number div 10;
digit := number mod 10;
sum := sum + digit;
writeln('Sum of digits: ', sum);
end;
end.