Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace P09.Multiply_Evens_by_Odds
- {
- class Program
- {
- private static void Main(string[] args)
- {
- int n = Math.Abs(int.Parse(Console.ReadLine()));
- int result = GetMultipleOfEvensAndOdds(n);
- Console.WriteLine(result);
- }
- private static int GetMultipleOfEvensAndOdds (int n)
- {
- int sumEvens = GetSumofEvenDigits(n);
- int sumOdds = GetSumofOddDigits(n);
- return sumEvens * sumOdds;
- }
- private static int GetSumofOddDigits (int n)
- {
- int oddSum = 0;
- while (n>0)
- {
- int lastDigit = n % 10;
- if (lastDigit%2 != 0)
- {
- oddSum += lastDigit;
- }
- n /= 10;
- }
- return oddSum;
- }
- private static int GetSumofEvenDigits (int n)
- {
- int evenSum = 0;
- while (n>0)
- {
- int lastDigit = n % 10;
- n /= 10;
- if (lastDigit % 2 == 0)
- {
- evenSum += lastDigit;
- }
- }
- return evenSum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment