Completed p2 in C and Java