C# Program to find the sum of even digits of a number


In this program, You will learn how to find the sum of even digits of a number in C#.


201454 = 2 + 4 + 4 => 10

693322 = 6 + 2 + 2 => 10

Example: How to find the sum of even digits of a number in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int n, r, s = 0;
		Console.Write("Enter a number:");
		n = Convert.ToInt32(Console.ReadLine());

		while (n > 0)
		{
			r = n % 10;
			if (r % 2 == 0){
        	s = s + r;
            }
			n = n / 10;
		}
		Console.WriteLine("Sum of even digits:" + s);
	}
}

Output:

Enter a number:2345
Sum of even digits:6