Assignment10
Problem 1
What is printed by the following function if n = 5?
void prints_things(int n) {
if(n < 3)
printf("First numbers - %d\n", n);
if ( n == 0 )
printf("I print things");
else
prints_things(n - 1);
printf("Last numbers - %d\n", n);
}
Problem 2
How many elements are in array foo? What is in the last element of foo?
void main(int) {
int foo[10];
for(int i = 0; i < 10; i++) {
foo[i] = 3*i;
}
return 0;
}
Problem 3
What is contained in the variable bar?
void main(int) {
int *bar;
int foo = 0;
bar = &foo;
return 0;
}
Program 1
Write a program that accepts 3 numbers from the user and prints the middle value. If there is a tie between any two numbers it instead indicates that no middle value exists.
Program 2
Build a N by M rectangle. You don't have to accept user input, but N and M should be easy to modify. For example a 7 by 5 rectangle looks like the example below. Note the spaces on the horizontal rows.
* * * * * * *
* *
* *
* *
* * * * * * *