Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int number;
- int sum = 0;
- printf("Enter a number: ");
- scanf("%d", &number);
- while (number != 0) {
- int digit = number % 10;
- sum += digit;
- number /= 10;
- }
- printf("Sum of digits: %d\n", sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment