Computer Science, asked by harshitagarwal9031, 8 months ago

4. Program to enter a number and print the sum of even digits present in number.
Sample input:- 672
Sum of even digits = 6+2 = 8​

Answers

Answered by Anonymous
1

The program output is also shown below.

int i, num, odd_sum = 0, even_sum = 0;

printf("Enter the value of num\n");

scanf("%d", &num);

for (i = 1; i <= num; i++)

if (i % 2 == 0)

even_sum = even_sum + i;

odd_sum = odd_sum + i;

printf("Sum of all odd numbers = %d\n", odd_sum);

Answered by adhikarirupesh70
5

Answer:

Let N be the input number.

Initialize sum = 0.

Repeat the following steps while N > 0

Set r = N % 10. Store the rightmost digit of N in r.

Set N = N / 10. Remove the rightmost digit of N.

If r is even, set sum = sum + r. If r is odd, do nothing.

The sum of even digits of N is stored in sum.

Explanation:

you can see format below

Similar questions