Files
C-Bootcamp-Tutorial/A10/78_Sum_of-triple_digits-Solution/main.c
T
2026-09-24 14:39:54 +02:00

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