25 lines
405 B
C
25 lines
405 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// 531 ---> 531 / 10 = 53
|
|
// units 1
|
|
// tens = 3
|
|
// hundreds = 5
|
|
|
|
int main()
|
|
{
|
|
int num;
|
|
int units, tens, hundreds;
|
|
|
|
printf("Enter a 3-digit number: ");
|
|
scanf("%d", &num);
|
|
|
|
units = num % 10;
|
|
tens = (num / 10) % 10;
|
|
|
|
hundreds = num / 100;
|
|
|
|
printf("The total sum of digits in %d is %d\n", num, units + tens + hundreds);
|
|
|
|
return 0;
|
|
} |