Hello Learner
Contributor
Stats
 Views : 4098 Comments : 0 Rating : 0
Actions

# write a .NET program to find the sum of odd-positioned digits and even-positioned digits of a given number

By Ashok Nalam on 18 Dec 2013 | Category: C# | Tagged: .NET number
The program finds the sum of odd-positioned digits and even-positioned digits of a given number using C#.NET example.
 Rate this resource

#### Introduction:

The program finds the sum of odd-positioned digits and even-positioned digits of a given number using C#.NET example.

E.g: If you enter number as 23456, so even number are 2,4,6  & Odd numbers are 3,5 and expected output should be
SumOfEven = 2+4+6 =12
SumOfOdd = 3+5 =8

#### Program:

```using System;
namespace DotNetMirror
{
class SumOfOddEvenDigitsOfNumber
{
static void Main()
{
Console.Write("Enter number to find sum of Even/Odd digits: ");
int orginalNumber = number;
int sumEven = 0; int sumOdd = 0;
int tempNumber = 0;
while (number != 0)
{
tempNumber = number % 10;
if (tempNumber % 2 == 0)
{
sumEven = sumEven + tempNumber;
}
else
{
sumOdd = sumOdd + tempNumber;
}
number = number / 10;
}
Console.WriteLine("Sum of Event numbers in '{0}' is:{1}", orginalNumber, sumEven);
Console.WriteLine("Sum of odd numbers in '{0}' is:{1}", orginalNumber, sumOdd);
}
}
}```

#### Ouput:

 Rate this resource