Imperative Programming HW1
Imperative Programming HW1
1. Log on to the lab system. After log in, open a terminal window. In this terminal you can type
commands. Start by creating a directory impprog that you will use for the course Imperative
Programming. You create this directory with the command:
mkdir impprog
2. Navigate to this directory using the command cd (change directory).
cd impprog
3. Create another directory week1, which is a subdirectory of impprog. Create in the directory
week1 another subdirectory hello and navigate to this directory:
mkdir week1
cd week1
mkdir hello
cd hello
Create the file hello.c using an editor (for example geany).
geany hello.c &
Type the following program, replace ... by the right information, and save it.
/* file: hello.c */
/* author: ...... (email: ....) */
/* date: ...... */
/* version: ..... */
/* Description: This program prints ’Hello world’ */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
1
6. If you are convinced that your program works well, you can submit it to the online assessment
system Justitia. You can reach Justitia via the link http://justitia.housing.rug.nl
using your favourite webbrowser. You have completed this first task once Justitia accepted your
submission.
2
of (1 + 7 + 10)/3 = 6.0 hours. If Peter chooses the order A, C, B then the average time drops to
(1 + 4 + 10)/3 = 5.0 hours. After some trying, Peter discovers that the order A, C, B is indeed the
order that results in a minimal average completion time, so he chooses this order.
Write a program that reads from the input the duration of three tasks (these are integer numbers)
and that prints on the output the minimal average completion time for these three tasks. The output
should be a floating point number rounded to one digit after the decimal dot.
Problem 5: Overlap
4
In the figure on the right, you see a grid containing two rectangles. 3 s
One rectangle is defined by the coordinates of the corner points 2
(0, 0) and (2, 3). The other rectangle is determined by the coor- 1 s
0 s
dinates (−2, 1) and (1, −2). Of course, the grid in the figure is
finite, but in reality the grid is assumed to be infinitely large. From -1
-2 s
the figure it is clear that the two rectangles overlap. We call two
-3
rectangles overlapping if they have at least one point in common,
-4
so two rectangles that touch each other are also overlapping. -4 -3 -2 -1 0 1 2 3 4
Make a program that first reads from the input the coordinates of the two corner points of a
rectangle, and then reads the two corner points of a second rectangle. You may assume that the
coordinates are grid points, i.e. their coordinates are integers. The program must print on the screen
whether the two rectangles overlap. Make sure that your program produces output in the exact same
format as given in the following examples.