Advertisement
skipter

C# Methods / Multiply odd by evens

Jun 13th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. namespace DataTypes___Lab
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             int number = Math.Abs(int.Parse(Console.ReadLine()));
  9.            
  10.             Console.WriteLine(GetSumOfOddDigits(number) * GetSumOfEvenDigits(number));
  11.         }        
  12.         static int GetSumOfOddDigits(int number)
  13.         {
  14.             int sum = 0;
  15.             while (number > 0)
  16.             {
  17.                 int lastDigit = number % 10;
  18.                 if (lastDigit % 2 != 0)
  19.                 {
  20.                     sum += lastDigit;
  21.                 }
  22.                 number /= 10;
  23.             }
  24.             return sum;
  25.         }
  26.         static int GetSumOfEvenDigits(int number)
  27.         {
  28.             int evenSum = 0;
  29.             while (number > 0)
  30.             {
  31.                 int lastDigit = number % 10;
  32.                 if (lastDigit % 2 == 0)
  33.                 {
  34.                     evenSum += lastDigit;
  35.                 }
  36.                 number /= 10;
  37.             }
  38.             return evenSum;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement