+ 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

2nd Dec 2023, 7:18 PM
♨⚠DabTop Grid⚠♨
♨⚠DabTop Grid⚠♨ - avatar
8 Answers
+ 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); }
2nd Dec 2023, 9:38 PM
SoloProg
SoloProg - avatar
+ 3
use an other variable for the output if u increse the num variable the loop will never end
2nd Dec 2023, 9:18 PM
Med Yassine
Med Yassine - avatar
+ 2
hey Share your code with proper description
2nd Dec 2023, 9:09 PM
SoloProg
SoloProg - avatar
+ 2
It's OK now with the code you sent me thx so much
2nd Dec 2023, 9:19 PM
♨⚠DabTop Grid⚠♨
♨⚠DabTop Grid⚠♨ - avatar
+ 1
this looks like an infinite loop
2nd Dec 2023, 9:14 PM
Med Yassine
Med Yassine - avatar
+ 1
int num= Convert.ToInt32(Console.ReadLine()); int out=1; for(int i=1;i<=num;i++){ out*=i; } Console.WriteLine(out);
2nd Dec 2023, 9:16 PM
Med Yassine
Med Yassine - avatar
0
int num = Convert.ToInt32(Console.ReadLine()); for (int i = 1; i < num; i++) { num*=i; Console.WriteLine(num); }
2nd Dec 2023, 9:12 PM
♨⚠DabTop Grid⚠♨
♨⚠DabTop Grid⚠♨ - avatar
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
2nd Dec 2023, 9:16 PM
♨⚠DabTop Grid⚠♨
♨⚠DabTop Grid⚠♨ - avatar