CoolInterview.com - World's Largest Collection of Interview Questions
Start Your Own website Now
Sponsored Links

Interview Questions
Our Services

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies


  • INTERVIEW QUESTIONS C ARRAYS IN C DETAILS
    Question :
    Write a program to insert an element in a linear array array?

    Posted by: pratyaksh on 8/19/2008

    Contact pratyaksh Contact pratyaksh
    Category Arrays in C Interview Questions
    Rating (0.4) By 1550 users
    Added on 8/19/2008
    Views 2239
    Rate it!
    Answers:

    /*Inserting an element into and deleting an element from an array*/
    #include<stdio.h>
    #include<conio.h>
    void display(int*,int);
    void insert(int*,int*,int,int);
    void del(int*,int*,int);
    int main()
    {
    int a[10],noe;
    int i,pos,nel;
    printf("
    Enter noe");
    scanf("%d",&noe);
    for(i=0;i<noe;i++)
    scanf("%d",&a[i]);
    display(a,noe);
    printf("
    Enter the position and element to be inserted");
    scanf("%d %d",&pos,&nel);
    insert(a,&noe,pos,nel);
    display(a,noe);
    del(a,&noe,pos);

    return 0;
    }
    void insert(int*p,int *noe,int pos,int nel)
    {
    int i;
    for(i=*noe;i>=pos;i--)
    {
    p[i]=p[i-1];
    }
    (*noe)++;
    p[i]=nel;
    }
    void display(int*p,int noe)
    {
    int i;
    for(i=0;i<noe;i++)
    printf("
    %d",p[i]);
    }



    Posted by: B.N.V.R.Ganesh    

    Contact B.N.V.R.Ganesh Contact B.N.V.R.Ganesh

    #include<stdio.h>
    #include<conio.h>

    void main()
    {

    int a[20],i,j,n;
    clrscr();
    printf("Enter the no of element you want to insert in the array : ");
    scanf("%d",&n);

    printf(" Enter the Array element : ");
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    }

    printf("The array is : ");
    for(i=0;i<n;i++)
    {
    printf("%d",a[i]);
    }
    printf(" Enter the element which you want to insert");
    scanf("%d",&j);

    printf("The array is : ");
    for(i=0;i<n+1;i++)
    {
    if(i==n)
    a[i]=j;
    printf("%d",a[i]);

    }
    getch();
    }



    Posted by: Nikhil jain    

    Contact Nikhil jain Contact Nikhil jain

    #include<stdio.h>
    #include<conio.h>
    int i,len,pos,num;
    main()
    {
    int a[100];
    void insert(int a[],int,int,int)
    clrscr();
    printf("enter integer to be read");
    scanf("%d",&len);
    printf("enter integer");
    for("i=0;i<len;i++)
    {
    scanf("%d",&a[i]);
    }
    printf("enter integer to be inserted");
    scanf("%d",&pos);
    --pos;
    getch();
    return 0;
    insert(a,len,pos,num);
    }
    void insert(int a[],int len,int pos,int num)
    {
    for(i=len;i>=pos;i--)
    {
    a[i+1]=a[i];
    }
    a[pos]=num;
    if(pos>len)
    {
    printf("insertion outside the array");
    }
    len++;
    printf("new array");
    for(i=0;i<len;i++)
    {
    printf("%d ",a[i]);
    }
    }



    Posted by: priti rachana    

    Contact priti rachana Contact priti rachana

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a[10],noe;
    int i,pos,ele;

    printf("Enter noe");
    scanf("%d",&noe);

    for(i=0;i<noe;i++)
    scanf("%d",&a[i]);

    printf("Enter the position and element to be inserted");
    scanf("%d%d",&pos,&ele);

    for(i=noe;i>=pos;i--)
    a[i]=a[i-1];

    a[pos-1]=ele;

    for(i=0;i<=noe;i++)
    printf(" %d",a[i]);

    getch();
    }



    Posted by: keerthan shetty    

    Contact keerthan shetty Contact keerthan shetty

    #include<stdio.h>
    #include<conio.h>
    void insert(int b[],int n,int pos,int item);
    void main()
    {
    int a[6]={10,20,30,40,50},p,c,item;
    printf("enter item and position for insertion");
    scanf("%d%d",&item,&p);
    printf("array before insertion");
    for(c=0;c<=4;c++)
    {
    printf("%d ",a[c]);
    }
    insert(a,6,p,item);
    printf("array after insertion");
    for(c=0;c<=5;c++)
    {
    printf("%d ",a[c]);
    }
    getch();
    }
    void(int b[],int n,int pos,int item)
    {
    int c;
    c=n-1;
    while(c>pos)
    {
    b[c]=b[c-1];
    c--;
    }
    b[c]=item;
    }



    Posted by: RENUKA    

    Contact RENUKA Contact RENUKA

    If you have the better answer, then send it to us. We will display your answer after the approval.
    Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       
    Related Questions
    View Answer
    Does mentioning the array name gives the base address in all the integers?
    View Answer
    How would you use qsort() function to sort the name stored in an array of pointers to string?
    View Answer
    Write a program for n lines
    1 2 3 4 5
    16 17 18 19 6
    15 24 25 30 7
    14 23 22 21 8
    13 12 11 10 9
    View Answer
    What is the difference between null array and an empty array?
    View Answer
    Code for swapping of two numbers without using temporary variable using C.
    View Answer
    Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?


    View Answer
    Can the sizeof operator be used to tell the size of an array passed to a function?


    View Answer
    How to remove duplicate elements from an array

    View Answer
    How can you sort the elements of the array in descending order?
    View Answer
    Array is an lvalue or not?
    View Answer
    Can the size of an array be declared at runtime?
    View Answer
    Can the sizeof operator be used to tell the size of an array passed to a function?
    View Answer
    Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
    View Answer
    When does the compiler not implicitly generate the address of the first element of an array?
    View Answer


    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL Arrays in C Interview Questions

    User Options
    Sponsored Links


    Copyright ©2003-2014 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes


    Cache = 0.015625 Seconds