The oxidation state of the C atom in HCN molecule is
+2
In compounds formed by the union of different elements, the more electronegative atom will have negative oxidation number whereas the less electronegative atom will have positive oxidation number.
Here N is more electronegative than C.
Further, the oxidation number of hydrogen is + 1 when combined with non-metals and is -1 when combined with active metals called metal hydrides such as LiH, KH, MgH2, CaH2 etc.
Therefore, the O. N. (N) = -3
O. N. (H) = +1
HCN ⟹ +1+n-3 = 0
⟹ C = 2