# A positive integer is entered from the keyboard. Calculate the sum of odd digits. (Pascal)

October 1, 2021 | education

| program calc;

var a, sum, k, code: integer;

// a – number, sum – the sum of odd digits,

// k is the position of the digit in the number, code is the error message.

s, s1: string; // s is a string of digits and s1 is a substring of digits at position k.

begin

writeln (‘Enter an integer’);

read (a); // enter a number

str (a, s); // converting numbers to string

sum: = 0;

for i: integer: = 1 to length (s) do

begin

s1: = copy (s, i, 1); // highlight a single digit

val (s1, k, Code); // convert a string-digit to a number

if k mod 2 = 1 then sum: = sum + k; // parity check and sum of odd digits

end;

writeln (‘The sum of odd digits is equal to’, sum)

end.

One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.