fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n;
  5. printf("Enter the number: ");
  6. scanf("%d",&n);
  7. int sum=0;
  8. int lastdigit=0;
  9. while(n!=0){
  10. lastdigit= n%10;
  11. if(lastdigit%2==0){
  12. sum=sum + lastdigit;
  13. }
  14. n=n/10;
  15. }
  16. printf("The sum of digits are %d",sum);
  17.  
  18.  
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 5316KB
stdin
121212
stdout
Enter the number: The sum of digits are 6