﻿ C# Sharp exercises: Program to display certain values of the function - w3resource

# C# Sharp Exercises: Program to display certain values of the function

## C# Sharp Basic Data Types: Exercise-6 with Solution

Write a C# Sharp program to display certain values of the function x = y2 + 2y + 1 (using integer numbers for y , ranging from -5 to +5).

Sample Solution:-

C# Sharp Code:

``````using System;
public class Exercise6
{
public static void Main()
{
int x, y;

Console.WriteLine("x = y² - 2y +1");
Console.WriteLine();

for (y=-5; y <= 5; y++)
{
x = y*y - 2*y + 1;
Console.WriteLine(
"y = {0} ; x=({0})² - 2*({0}) +1 = {1}",
y, x);
}
}
}
```
```

Sample Output:

```x = y² - 2y +1
y = -5 ; x=(-5)² - 2*(-5) +1 = 36
y = -4 ; x=(-4)² - 2*(-4) +1 = 25
y = -3 ; x=(-3)² - 2*(-3) +1 = 16
y = -2 ; x=(-2)² - 2*(-2) +1 = 9
y = -1 ; x=(-1)² - 2*(-1) +1 = 4
y = 0 ; x=(0)² - 2*(0) +1 = 1
y = 1 ; x=(1)² - 2*(1) +1 = 0
y = 2 ; x=(2)² - 2*(2) +1 = 1
y = 3 ; x=(3)² - 2*(3) +1 = 4
y = 4 ; x=(4)² - 2*(4) +1 = 9
y = 5 ; x=(5)² - 2*(5) +1 = 16
```

Flowchart:

C# Sharp Code Editor: