In addition to Kees' comment, we don't as a general rule, give out answers to homework questions here. If you can't figure out the assignment on your own, try talking to the professor or teaching assistants for the course. If you still can't figure it out, it might be an indication that you're not cut out to be a programmer. There's no shame in that, unless you don't recognize and accept your limits and find something you are better suited for. We all have our inherent talents and blind spots; things that I find ridiculously simple might be impossibly complex for someone else and the reverse is likely true in a different context.
If we just gave everyone the answer who came here asking, not only are we facilitating what most Universities would consider intellectual dishonesty, punishable by you instantly flunking the course (best case) or expulsion (worst case), but we would be doing you and your classmates a disservice. When you get a degree, it is supposed to represent that you have obtained a certain base level of knowledge, but if you had people doing your assignments for you, you didn't actually learn everything for that degree, did you? So you might get a job and your employer wants you to write a semaphore for them. Then, after they fire you because you misrepresented yourself and your skills, they might be wary of hiring anyone else with a degree from the same University. Meaning that the degree everyone else gets from that University is now worth less because employers have discovered that not everyone with that degree actually knows everything they claim to have learned. Do you really want to be that person?
There's absolutely nothing wrong with finding out that you're not cut out to be a programmer unless you let pride and ego prevent you from seeking out a different degree.