kucheasysa

sum of digits

Jun 6th, 2023
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int number;
  5. int sum = 0;
  6.  
  7. printf("Enter a number: ");
  8. scanf("%d", &number);
  9.  
  10. while (number != 0) {
  11. int digit = number % 10;
  12. sum += digit;
  13. number /= 10;
  14. }
  15.  
  16. printf("Sum of digits: %d\n", sum);
  17.  
  18. return 0;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment