Saturday, December 8, 2018

VALUE INSERTION IN THE ARRAY

  • Problem Description
    Write a program using pointers to insert a value in an array.
    Input and Output Format:
    Refer sample input and output for formatting specification.
    All float values are displayed correct to 2 decimal places.
    All text in bold corresponds to input and the rest corresponds to output.
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
       int j,i,n,b;
       scanf("%d", &n);
       int a[n];
       for (i=0;i<n;i++){
          scanf("%d",&a[i]);
       }
       scanf("%d", &b);
       scanf("%d", &j);
       for (i=n-1;i>=j-1;i--)
       {
          a[i+1] = a[i]; }
          a[j-1]=b;
       for (i=0;i<=n;i++){
          printf("%d\n",a[i]);
       }
       return 0;

    }
  • Test Case 1
    Input (stdin)
    3
    99 199 299
    399
    1
    Expected Output
    399
    99
    199
    299
  • Test Case 2
    Input (stdin)
    4
    1 2 3 4
    5
    2
    Expected Output
    1
    5
    2
    3
    4

2 comments: