Exercise 1 (written):
- Write a function which returns twice the input
- Write a function which return the negative of its input
Exercise 2: What value is output (returned) by
PlusOne(-1)
?
0
- Write a
C
function which takes a input a a single integer parameter returns twice the value.
int Twice(int x)
{
return 2 * x;
}
- Write a
C
function which returns takes a single integer input parameter returns twice the value of it.
int Negative(int x)
{
return -x;
}
- Write a
C
function which takes two integer parameters and returns the first minus the second
int Subtract(int a, int b)
{
return a - b;
}
Exercise 4: What is the value returned by
AddThreeTimes_v2(11)
?
11 + 10 + 10 + 10 = 41
Exercise 5: Write a function that takes a
double
namedradius
as input and returns a double which is the area of a circle with that radius. (hint: you can approximateas 3.1412)
double CircleArea(double radius)
{
double pi = 3.1412;
return pi * radius * radius;
}
Of course its OK if oyu named your function differently, or maybe didn't have the separate line defining a variable for pi
.