Computer Science, asked by sukh1121, 6 months ago

write a program to input a number and find the sum of all even digits​

Answers

Answered by as1691503
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 jai696
4

\large\mathsf\color{pink}{Solution\: using\: python\: 3}

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)}")

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions