✍️ Practice (Medium)
1. f of x
Write a function which helps apply this formula:
Then, use it to evaluate for the values of :
👀Hints
Be sure to respect variable naming conventions! In math we may write however this isn't a valid way to write a C# function!
💡Solution
Function Definition:
static int FQuadratic(int x)
{
int term1 = x - 4;
int term2 = x + 7;
return term1 * term2;
}
Function Call:
Console.WriteLine(FQuadratic(4)); // prints 0
Console.WriteLine(FQuadratic(-7)); // prints 0
Console.WriteLine(FQuadratic(2)); // prints -18
Console.WriteLine(FQuadratic(-6)); // prints -10
2. Melon Farm
You are cultivating a melon farm in minecraft and need to figure out your total farmable area.
Write a function to calculate the area of a rectangle:
💡Solution
static int RectangleArea(int width, int height)
{
return width * height;
}
Write a function to calculate the area of a square:
💡Solution
static int SquareArea(int side)
{
return side * side;
}
Using the functions from before, calculate the total farmable area of your melon farm

💡Solution
int plotArea = RectangleArea(6, 12); // 72
int pondArea = SquareArea(2); // 4
int farmableArea = plotArea - (2 * pondArea);
Console.WriteLine(farmableArea); // prints 64
3. Tracing Trash
Consider the following code:
static void Main()
{
int a = 2, b = 3, c = 4;
Snowing (a, b, c);
Snowing (c, b, b);
Snowing (a, c, a);
}
static void Snowing (int r, int grapes, int g)
{
int mylocal;
mylocal = (r + grapes) * g;
Console.WriteLine("You passed in " + r + " and " + grapes + " and " + g);
Console.WriteLine("Your output is: " + mylocal);
}
What will be the output when running this:
Main();
👀Hints
Determine the output without running the code. Only after coming up with an answer, run the code to see if you were correct. If you got the wrong answer, use the debugger to step through the code to see where you went wrong.
💡Solution
You passed in 2 and 3 and 4
Your output is: 20
You passed in 4 and 3 and 3
Your output is: 21
You passed in 2 and 4 and 2
Your output is: 12
4. Tracing Garbage
Consider the following code:
static void Main()
{
int x = 2, y = 4, z = 7;
double a = 0, b = 0;
a = Crazy(z, y, y);
b = Crazy(y, x, z) + Crazy(x, y, z);
Console.WriteLine("I see 'a' as " + a + " and 'b' as " + b);
}
static double Crazy (int y, int x, int z)
{
double mylocal;
mylocal = x - y;
mylocal *= 2;
mylocal += z;
return mylocal;
}
What will be the output when running this:
Main();
👀Hints
Determine the output without running the code. Only after coming up with an answer, run the code to see if you were correct. If you got the wrong answer, use the debugger to step through the code to see where you went wrong.
💡Solution
I see 'a' as -2 and 'b' as 14
5. Tracing Absolute Junk
Consider the following code:
static void Main() {
int a = 5, b = 4, c = 9;
a = AddEmUp(b, c, c);
c = a + AddEmUp(a, c, b);
b = AddEmUp(a, a, a) + b;
Console.WriteLine("a = " + a + " b = " + b + " c = " + c);
}
static int AddEmUp (int da, int db, int dc)
{
int anothervar;
anothervar = (da * 2) + db - dc;
// more code here
return anothervar;
} // end of void myfunc
What will be the output when running this:
Main();
👀Hints
Determine the output without running the code. Only after coming up with an answer, run the code to see if you were correct. If you got the wrong answer, use the debugger to step through the code to see where you went wrong.
💡Solution
a = 8 b = 20 c = 29