Advertisement
DeeAG

10.MultiplyEvensByOdds

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