What output did you expect? Sorry, I know nothing about cofactors so I don't know.
Have you tried adding debug statements to the code to determine where the silly values are coming from? For example you can display the values in the first for loop with something like:
Code:
  printf("Assigning a[i=%d][j=%d]=%d to b[i][j]\n", i, j, a[i][j]);
  b[i][j]=a[i][j];
I'm sorry, but I don't know how to teach you more elaborately about a scanf replacement than by directly giving you the code. Could you clarify what exactly you're expecting?