Wednesday, 13 August 2014

Inserting.... please help me to rectify the error


#include<stdio.h>
#include<conio.h>
int main(){
    int a[20],lm,temp[20];
    int i,j,position,element;
    printf("Enter the No of elements of the array:");
    scanf("%d",&lm);
    printf("Enter the array elements:\n");
    for(i=0;i<lm;i++){
                      scanf("%d", &a[i]);
                      }
    printf("Enter the position & element to be inserted:");
    scanf("%d %d ", &position, &element);
    j=position-1;
    printf("\n Before Inserting:\n");
    for(i=0;i<lm;i++){
                      printf("%d", a[i]);
                      temp[i]=a[i];
                      }
    for(i=position;i<=lm;i++){
                            temp[i]=a[j];
                            j++;
                            }
    temp[position-1]=element;
    printf("\n After Inserting\n");
    for(i=0;i<=lm;i++){
                       printf("%d", temp[i]);
                       }
     return 0;      
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.