fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, digit, sum = 0;
  6.  
  7. scanf("%d", &n);
  8.  
  9. while (n != 0)
  10. {
  11. digit = n % 10;
  12.  
  13. if (digit % 2 == 0)
  14. {
  15. sum = sum + digit;
  16. }
  17.  
  18. n = n / 10;
  19. }
  20.  
  21. printf("Sum of even digits = %d\n", sum);
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Sum of even digits = 8