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]=b;for (i=0;i<=n;i++){printf("%d\n",a[i]);}return 0;}
Test Case 1
Input (stdin)399 199 2993991Expected Output99399199299Test Case 2
Input (stdin)41 2 3 452Expected Output12534
This blog is to help for the programmers to learn the programs and not to demotivate any people .Our intention is to make the learners to learn the code easily.Next UPDATE (TODAY 2pm).For further updates follow us.Comment your doubts we'll help you as soon as possible..
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)399 199 2993991Expected Output39999199299Test Case 2
Input (stdin)41 2 3 452Expected Output15234
Subscribe to:
Posts (Atom)