Answer the question
In order to leave comments, you need to log in
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
static void Fact(int number, out int result)
{
result = 1;
while(number!=1)
{
result *= number;
number--;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question