I'm supposed to write a program that will use insertion sort to sort 12 numbers in an array. Right now my program will sort the numbers but always has 12 at the end even if it is not inputted and negative numbers are not working. can anybody help me out?
Here's what i have so far.
Code:
#include <stdio.h>
int main(void)
{
int a[12];
int z = 0, b = 1, j, temp;
while( b <= 12){
printf("Enter number %d: ", b);
scanf("%d", &a[z]);
for(z = 1; z <b; z++)
{
temp = a[z];
j = z - 1;
while(temp<a[j] && j >=0)
{
a[j + 1] = a[j];
j = j - 1;
}
a[j +1] = temp;
}
z++;
b++;
}
for(z = 0; z <=b; z++){
printf("%d\t", a[z]);
z++;}
return 0;
}
Thanks!