Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program to insert new value in the array at desired position.
- And print the array. Follow the sample input and output to get your concept cleared.
- Input: 5
- 10 20 30 40 50
- 77 3
- Output: 10 20 77 30 40 50
- */
- #include<stdio.h>
- int main()
- {
- int n,i;
- scanf("%d", &n);
- int ara[n];
- ///INPUTING ARRAY
- for(i=0; i<n; i++)
- {
- scanf("%d", ara[i]);
- }
- ///ADD AN ELEMENT
- int index, numb;
- scanf("%d %d", &index, &numb);
- int ara2[n+1];
- for(i=0; i<index; i++)
- {
- ara2[i]= ara[i];
- }
- ara2[index] = numb;
- for(i= index+1; i<n+1; i++)
- {
- ara2[i] = ara[i-1];
- }
- ///PRINTING ARRAY
- for(i=0; i<n+1; i++)
- {
- printf("%d ", ara2[i]);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment