Pointer - 20

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. Test Case 1 Input (stdin) 3 99 199 299 399 1 Expected Output 99 399 199 299 Test Case 2 Input (stdin) 4 1 2 3 4 5 2 Expected Output 1 2 5 3 4

Program :

  • #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]=b;

       for (i=0;i<=n;i++){

          printf("%d\n",a[i]);

       }

       return 0;


    }