Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Herausforderung: For-Schleife | Schleifen
C# Grundlagen

bookHerausforderung: For-Schleife

Erstellen Sie ein Programm, das die Fakultät einer gegebenen Zahl x mit einer for-Schleife berechnet. Wenn die Zahl 0 ist, soll das Programm 1 zurückgeben.

main.cs

main.cs

copy
12345678910111213141516171819202122232425262728
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int x = 5; int result = ___; if(x == 0) { result = ___; } else { for (___) { result *= ___; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }

Initialisieren Sie die Schleifenvariable i mit dem Wert 2 und führen Sie die Schleife aus, bis i gleich x ist. Die Schleifenbedingung lautet also i <= x.

main.cs

main.cs

copy
12345678910111213141516171819202122232425262728
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int x = 5; int result = 1; if(x == 0) { result = 0; } else { for (int i = 2; i <= x; i++) { result *= i; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you show me an example of how the program should work with a specific number?

What should the program do if the input is a negative number?

Can you explain why the loop starts at 2 instead of 1?

Awesome!

Completion rate improved to 1.59

bookHerausforderung: For-Schleife

Swipe um das Menü anzuzeigen

Erstellen Sie ein Programm, das die Fakultät einer gegebenen Zahl x mit einer for-Schleife berechnet. Wenn die Zahl 0 ist, soll das Programm 1 zurückgeben.

main.cs

main.cs

copy
12345678910111213141516171819202122232425262728
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int x = 5; int result = ___; if(x == 0) { result = ___; } else { for (___) { result *= ___; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }

Initialisieren Sie die Schleifenvariable i mit dem Wert 2 und führen Sie die Schleife aus, bis i gleich x ist. Die Schleifenbedingung lautet also i <= x.

main.cs

main.cs

copy
12345678910111213141516171819202122232425262728
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int x = 5; int result = 1; if(x == 0) { result = 0; } else { for (int i = 2; i <= x; i++) { result *= i; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 2
some-alt