Професионална програма
Loading...
zhelyazko777 avatar zhelyazko777 0 Точки

Multiply Evens by Odds

Здравейте колеги, някой ще може ли да ми каже къде ми е грешката в този код: https://pastebin.com/vuw1Jth5

Става въпрос за тази задача: https://judge.softuni.bg/Contests/Practice/Index/304#8 

 

Тагове:
0
Fundamentals Module
koknq avatar koknq 24 Точки

using System;
using System.Linq;
namespace ConsoleApp17
{
    class Program
    {
        static void Main(string[] args)
        {
            string n = Console.ReadLine();
            int[] array = new int[n.Length];
            int startindex = 0;
            if (n[0] == '-')
            {
                startindex = 1;
                for (int i = startindex; i < n.Length; i++)
                {
                    array[i] = int.Parse(n[i].ToString());
                }
            }
            else
            {
                for (int i = 0; i < n.Length; i++)
                {
                    array[i] = int.Parse(n[i].ToString());

                }
            }


            double result = Multiply(array);
            Console.WriteLine(result);
        }
        static int Multiply(int[] array)
        {
            int result = GetSumOfEvenDigits(array) * GetSumOfOddDigits(array);
            return result;
        }

        static int GetSumOfOddDigits(int[] array)
        {
            int sumOdd = 0;
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] % 2 != 0)
                {
                    sumOdd += array[i];
                }
            }
            return sumOdd;
        }
        static int GetSumOfEvenDigits(int[] array)
        {
            int sumEven = 0;
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] % 2 == 0)
                {
                    sumEven += array[i];
                }
            }
            return sumEven;
        }
    }
}

0