BubaLazi

Multiply Evens by Odds

Jul 8th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8.  
  9. namespace ConsoleApp1
  10. {
  11.     class Program
  12.     {
  13.  
  14.  
  15.         static void Main()
  16.         {
  17.             int n = Math.Abs(int.Parse(Console.ReadLine()));
  18.             int result = GetMultipleOfEvenAndOdds(n);
  19.             Console.WriteLine(result);
  20.            
  21.         }
  22.  
  23.         static int GetMultipleOfEvenAndOdds(int n)
  24.         {
  25.             int sumEven = GetSumOfEvenDigits(n);
  26.             int sumOdd = GetSumOfOddDigits(n);
  27.             return sumEven * sumOdd;
  28.  
  29.         }
  30.  
  31.         static int GetSumOfEvenDigits(int n)
  32.         {
  33.  
  34.             int sum = 0;
  35.             while( n > 0)
  36.             {
  37.                 int lastDigit = n % 10;
  38.                 if(lastDigit %2 != 0)
  39.                 {
  40.                     sum = sum + lastDigit;
  41.                 }
  42.                 n /= 10;
  43.             }
  44.             return sum;
  45.         }
  46.         static int GetSumOfOddDigits(int n)
  47.         {
  48.  
  49.             int sum = 0;
  50.             while (n > 0)
  51.             {
  52.                 int lastDigit = n % 10;
  53.                 if (lastDigit % 2 == 0)
  54.                 {
  55.                     sum = sum + lastDigit;
  56.                 }
  57.                 n /= 10;
  58.             }
  59.             return sum;
  60.         }
  61.  
  62.  
  63.  
  64.     }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment