I would just have an array correct filled with zeros and size of number of total classes. Then I would classify data point j, if it matches the target label[j] then just increment the array with that class index, correct[j] += 1. If num_class is an array that contains the number of points for each class c, then the accuarcy is correct[c] / num_class[c].