the above program is for INSERTING AN ELEMENT INTO AN ARRAY.but when i run this code it gives me very weird output....it doesn't print the "enter the element after which the number has to be inserted "line and also when i enter choce 1.that means inCode:#include<stdio.h> #include<conio.h> void main() { int a[11],i,j,k,ch,sh,e; clrscr(); printf("enter array elements:"); for(i=0;i<10;i++) scanf("%d",&a[i]); printf("enter choice\n1.in between insertion\n2.insertion in the beginning\n3.insertion at the end"); scanf("%d",&ch); switch(ch) {case1: printf("enter the element:"); scanf("%d",&e); printf("enter the element after which the number has to be inserted:"); scanf("%d",&sh); for(i=0;i<10;i++) { if(a[i]==sh)//finding the element break; } for(k=9;k>i;k--) a[k+1]=a[k];//shifting the element a[i+1]=e; break; case2: printf("enter the element:"); scanf("%d",&e); for(k=9;k>=0;k--) a[k+1]=a[k]; a[0]=e; break; case3: printf("enter the element:"); scanf("%d",&e); a[10]=e; } printf("\n"); for(i=0;i<11;i++)//display the result printf("%d",a[i]); getch(); }
between insertion//
the output is like:
enter the array:
1 2 3 4 5 6 7 8 9 10
enter the choice:1.in between 2.in the beginning 3.at the end.
when i enter choice 1.in bwetween it prints..enter the element:suppose i enter 30
then it immediately prints
array after insertion is:1 2 3 4 5 6 7 8 9 10 30 52 33 30
and the same output for in beginning and at the end....what do i do now?where is the error?i don't know plz help me out ??/