ported ex1.c