gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Write a program in C# that takes three numbers as input and outputs the maximum of those…
- User
Write a program in C# that takes three numbers as input and outputs the maximum of those numbers through a loop.
- Assistant
Here is a program in C# that takes three numbers as input and outputs the maximum of those numbers using a loop:
csharpusing System; class Program { static void Main(string[] args) { int max = int.MinValue; // Initialize max with the smallest possible integer value for (int i = 1; i <= 3; i++) { Console.Write("Enter number " + i + ": "); int num = Convert.ToInt32(Console.ReadLine()); if (num > max) { max = num; } } Console.WriteLine("The maximum number is: " + max); } }In this program, we use a for loop to iterate three times, each time taking a number as input and checking if it is greater than the current maximum (
max). If the input number is greater, it updates themaxvariable. Once the loop ends, we output the maximum number.