#include <iostream> using namespace std; typedef unsigned short int USI;
USI DigitCount(USI n) { USI a = (int) n / 100, bc = n % 100, b = (int) bc / 10, c = n % 10; if (a > 0) return 3; if (b > 0) return 2; if (c > 0) return 1; return 0; }
USI SumDigits(USI n, USI dc) { USI sum = 0, a, bc, b, c; switch (dc) { case 3: a = (int) n / 100; sum += a; case 2: bc = n % 100; b = (int) bc / 10; sum += b; case 1: c = n % 10; sum += c; break; default: return 0; break; } return sum; }
USI LastDigit(USI n) { return n % 10; }
USI FirstDigit(USI n, USI dc) { switch (dc) { case 1: return n; break; case 2: return (int) n / 10; break; case 3: return (int) n / 100; break; default: return 0; break; } }
k = 5;
var
x: array [1..k] of integer;
i, min_index, k2: integer;
begin
writeln('Enter x:');
for i := 1 to k do
begin
write('x[', i, '] = ');
readln(x[i]);
end;
min_index := 1;
k2 := 0;
for i := 1 to k do
begin
if x[min_index] > x[i] then
min_index := i;
if x[i] mod 2 = 0 then
k2 := k2 + 1;
end;
if k2 > 0 then
x[min_index] := k2;
writeln('x:');
for i := 1 to k do
writeln('x[', i, '] = ', x[i]);
writeln('k2 = ', k2);
writeln('min = ', x[min_index]);
end.
using namespace std;
typedef unsigned short int USI;
USI DigitCount(USI n) {
USI a = (int) n / 100,
bc = n % 100,
b = (int) bc / 10,
c = n % 10;
if (a > 0) return 3;
if (b > 0) return 2;
if (c > 0) return 1;
return 0;
}
USI SumDigits(USI n, USI dc) {
USI sum = 0,
a,
bc,
b,
c;
switch (dc) {
case 3:
a = (int) n / 100;
sum += a;
case 2:
bc = n % 100;
b = (int) bc / 10;
sum += b;
case 1:
c = n % 10;
sum += c;
break;
default:
return 0;
break;
}
return sum;
}
USI LastDigit(USI n) {
return n % 10;
}
USI FirstDigit(USI n, USI dc) {
switch (dc) {
case 1:
return n;
break;
case 2:
return (int) n / 10;
break;
case 3:
return (int) n / 100;
break;
default:
return 0;
break;
}
}
int main() {
USI n;
cout << "n = ";
cin >> n;
USI dc = DigitCount(n);
cout << "Число " << n
<< ":\n"
<< "Цифр: "
<< dc << '\n'
<< "Сумма цифр: "
<< SumDigits(n, dc) << '\n'
<< "Последняя цифра: "
<< LastDigit(n) << '\n'
<< "Первая цифра: "
<< FirstDigit(n, dc) << '\n';
return 0;
}