The nice thing about OpenMP is that most programs can still be run serially and you should get the correct result. It you do this with the OpenMP code that you posted, you don't get the correct result. That means that it is not the OpenMP part that is causing the problem. You are correct in your comment about it being your use of the variable "temp", because if you just add the OpenMP pragma to your serial code and run it in parallel, it works fine. I understand why you want to use temp to do the assignments, since it will be private to the thread and reduce possible cache conflicts. If you look at the loops closely you should see your problem.
The OpenMP ARB has made it a policy not to do homework for students and while I am not positive that you are a student, this is a common program assignment for intro parallel programming courses.