write a program to input a number and find the sum of all even digits
Answers
Answered by
2
Answer:
#include<stdio.h>
int main(){
int num,rem,even=0,digit,input;
printf(" Enter an integer number: ");
scanf("%d",&num);
input = num;
num = abs(num);
while(num>0){
digit = num % 10;
num = num / 10;
rem = digit % 2;
if(rem == 0)
even=even+digit;
}
printf("\n The sum of even digits present in %d is %d.",input,even);
return 0;
}
Explanation:
pls follow me
Answered by
4
def sum_even_digits(n):
_sum = 0
even_nums = [int(n) for n in str(n) if int(n) % 2 == 0]
for n in even_nums:
_sum += n
return _sum
n = int(input("enter n: "))
print(f"sum: {sum_even_digits(n)}")
Similar questions