anizko

10. Multiply Evens by Odds

Jul 2nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _10._Multiply_Evens_by_Odds
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int number = int.Parse(Console.ReadLine());
  11.             number = Math.Abs(number);
  12.             int multipleOfEvenAndOdds =
  13.                 GetMultipleOfEvenAndOdds(GetSumOfEvenDigits(number), GetSumOfOddDigits(number));
  14.  
  15.  
  16.             Console.WriteLine(multipleOfEvenAndOdds);
  17.         }
  18.  
  19.         static int GetSumOfEvenDigits(int number)
  20.         {
  21.             int sumEvenDigits = 0;
  22.             while (number > 0)
  23.             {
  24.                 int curruntDigit = number % 10;
  25.                 number /= 10;
  26.  
  27.                 if (curruntDigit % 2 == 0)
  28.                 {
  29.                     sumEvenDigits += curruntDigit;
  30.                 }
  31.             }
  32.             return sumEvenDigits;
  33.         }
  34.  
  35.         static int GetSumOfOddDigits(int number)
  36.         {
  37.             int sumOddDigits = 0;
  38.             while (number > 0)
  39.             {
  40.                 int curruntDigit = number % 10;
  41.                 number /= 10;
  42.  
  43.                 if (curruntDigit % 2 != 0)
  44.                 {
  45.                     sumOddDigits += curruntDigit;
  46.                 }
  47.             }
  48.             return sumOddDigits;
  49.         }
  50.         static int GetMultipleOfEvenAndOdds(int sumOddDigits, int sumEvenDigits)
  51.         {
  52.             int multipleOfEvenAndOdds = sumOddDigits * sumEvenDigits;
  53.             return multipleOfEvenAndOdds;
  54.         }
  55.  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment