using System; // Import the System namespace to use basic classes like Console
class Program // Define the main class of the program
{
static void Main() // The entry point of the program
{
// Iterate over integer values of x from -10 to 10
for (int x = -10; x <= 10; x++) // Start from x = -10 and loop until x = 10
{
// Calculate the value of the function y = x^2 - 2x + 1
int y = (x * x) - (2 * x) + 1; // Function formula: y = x^2 - 2x + 1
// Display the value of x and the corresponding y
Console.WriteLine($"For x = {x}, y = {y}"); // Output the result for the current value of x
}
}
}
Salida
For x = -10, y = 121
For x = -9, y = 100
For x = -8, y = 81
For x = -7, y = 64
For x = -6, y = 49
For x = -5, y = 36
For x = -4, y = 25
For x = -3, y = 16
For x = -2, y = 9
For x = -1, y = 4
For x = 0, y = 1
For x = 1, y = 0
For x = 2, y = 1
For x = 3, y = 4
For x = 4, y = 9
For x = 5, y = 16
For x = 6, y = 25
For x = 7, y = 36
For x = 8, y = 49
For x = 9, y = 64
For x = 10, y = 81
Código de Ejemplo Copiado!