A) What the heck am I doing here? is a question to someone else. = Why am I here in the first place? / Why did you call me here for this meeting?
B) What the heck I am doing here. is an exclamation statement. = "What the heck am I doing here!" = rhetorical (note "I am" vs. "am I" in the statement).
and the last question is "a or the"
Always "the heck" for me, in AmE.