+ 1
C# Lesson in Loops
Im really confused in the quiz with the factorial and I don't know how to solve it. I tried lot of times, I was to close but the result wasn't right and I really need help because I'm stuck. If someone know the correct code please send me and explain!! Thanks
8 Antworten
+ 4
// Try this
int num = Convert.ToInt32(Console.ReadLine());
for(int i=1;i<=num;i++){
Console.WriteLine(factorial(i));
}
int factorial(int x) {
if (x<=1) return 1;
return x * factorial(x-1);
}
+ 3
use an other variable for the output
if u increse the num variable the loop will never end
+ 2
hey
Share your code with proper description
+ 2
It's OK now with the code you sent me thx so much
+ 1
this looks like an infinite loop
+ 1
int num= Convert.ToInt32(Console.ReadLine());
int out=1;
for(int i=1;i<=num;i++){
out*=i;
}
Console.WriteLine(out);
0
int num = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i < num; i++)
{
num*=i;
Console.WriteLine(num);
}
0
Well in the third case which is 2 it shows it is correct my output is 2 but for example in case 4 witch is for it is the output is expected to be 24 but it goes 4 8 24... Idk how to fix it