#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; } }
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;
}