B
B
bpGusar2018-04-29 19:32:52
C++ / C#
bpGusar, 2018-04-29 19:32:52

Is it correct in this example to return the result through a parameter?

The meaning is this: find the factorial of a given number and output the result through a parameter.
I'm a noob in Sharpe, please explain if something is done wrong. Thank you!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomMethodsOfClass
{
    class Program
    {
        static void Factorial1(int number)
        {
            
            int factorial = 1;
            for (int i = 1; i <= number; i++)
            {
                factorial *= i;
                if (i == number)
                {
                    Console.Write("{0}", i);
                }
                else
                {
                    Console.Write("{0} * ", i);
                }
            }
            Console.Write(" = {0}", factorial);
            Console.ReadKey();
        }

        static void Main(string[] args)
        {
            Console.Write("Введите число : ");
            int number = int.Parse(Console.ReadLine());
            Factorial1(number);
        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2018-04-29
@Morpheus_God

static void Fact(int number, out int result)
        {
            result = 1;
            while(number!=1)
            {
                result *= number;
                number--;
            }
        }

A
Alexander, 2018-04-29
@alexr64

No. See the second and third headings here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question