Advertisement
knoteva

Untitled

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