Софтуерно Инженерство
Loading...
danail2003 avatar danail2003 2 Точки

Factorial Division

Здравейте, дава ми 30/100, ако може някой да ми помогне.

1.Factorial Division

Read two integer numbers. Calculate factorial of each number. Divide the first result by the second and print the division formatted to the second decimal point.

Examples

Input

Output

 

Input

Output

5

2

60.00

 

6

2

360.00

 

 

using System;

namespace Factorial_Division
{
    class Program
    {
        static void Main(string[] args)
        {
            long factorialNumber = long.Parse(Console.ReadLine());
            long divider = long.Parse(Console.ReadLine());         
            DiviseNumbers(factorialNumber, divider);
        }

        static void DiviseNumbers(long factorialNumber, long divider)
        {
            long multiply = 1;

            for (int i = 2; i <= factorialNumber; i++)
            {
                multiply *= i;
            }

            long result = multiply / divider;
            Console.WriteLine($"{result:f2}");
        }
    }
}

0
Programming Fundamentals
mark79 avatar mark79 347 Точки

Здравей,

ето ти примерно решение, предполагам можеш да видиш къде е разликата

        static long DiviseNumbers(int n)
        {
            if (n == 0)
                return 1;
            else
                return (n * DiviseNumbers(n - 1));
        }

        static void Main(string[] args)
        {
            int factorialNumber = int.Parse(Console.ReadLine());
            int divider = int.Parse(Console.ReadLine());

            double result = (double)DiviseNumbers(factorialNumber) / DiviseNumbers(divider);
            Console.WriteLine($"{result:f2}");
        }

Поздрави :)

PS -> Ако рекурсията не е ясна, може и така

        static long DiviseNumbers(int factorialNumber)
        {
            long multiply = 1;
            for (int i = 2; i <= factorialNumber; i++)
            {
                multiply *= i;
            }
            return multiply;
        }

 

0
25/08/2019 22:48:44
Ronn91 avatar Ronn91 -1 Точки

I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that’s at the other blogs.

basketball games

-1
danail2003 avatar danail2003 2 Точки

Благодаря !

0