function codes for lab6_2.c