Decomposition of three-digit number#935

Decomposition of three-digit number (Editorial)

Algorithm Analysis

Let n be a three-digit number. Then:

The input number n can be negative. Therefore, before finding its digits, its absolute value should be calculated.

Algorithm Implementation

Read the input value n. If it is negative, change the sign to positive.

scanf("%d", &n);
if (n < 0) n = -n;

Find the digits of the number.

a = n / 100;
b = n / 10 % 10;
c = n % 10;

Print each digit of the number in a separate line.

printf("%d\n%d\n%d\n", a, b, c);