Digits of a Number
Completed
Read a three-digit number and print its digits separated by spaces, then their sum.
Input
One integer 100–999.
Output
Two lines.
Example
Input
472
Output
4 7 2 13
Editor
C
Hints
n % 10 is the last digit; n / 10 removes it.
Solution explanation
Dividing by powers of ten shifts the digits right.
Show solution
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int a = n / 100, b = n / 10 % 10, c = n % 10;
printf("%d %d %d\n", a, b, c);
printf("%d\n", a + b + c);
return 0;
}