❔ factorial using equation
So i am stuck on this task where i have to also use equation for example
11 =1
12=2
23=6
and i still don't get the for cycles/loops so im struggling on finish product, i have almost everything except the 1st number which is last factorials anserw.
as of right now it is
11=1
22=2
63=6
here is the code i have right now, it has mistakes i know but im learning.
static void Main(string[] args)
{
Console.WriteLine("Please enter your number: ");
int n = int.Parse(Console.ReadLine());
int factorial = 1;
int factorialres = 1;
for (int i = 1; i <= n; i++)
{
factorial = i;
factorialres = factorial;
Console.WriteLine(factorialres + "" + i + " = " +factorial);
}
}
2 Replies
you are assigning the value of
i
to factorial
in each iteration of the loop, which is incorrect. you need to multiply the current value of factorial
with the value of i
.
here is the correct way you can do it
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.