mhdew

Array Insert using Function

Dec 21st, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int insert(int n, int a[], int position)
  4. {
  5. int j;
  6.  
  7. for(j=n;j>=position;j--){
  8. a[j+1]=a[j];
  9. }
  10.  
  11. scanf("%d", &a[position]);
  12.  
  13. for(j=0;j<=n;j++){
  14. printf("%d ", a[j]);
  15. }
  16. printf("\n");
  17. }
  18.  
  19. int main()
  20. {
  21. int i, n;
  22. int position;
  23. int a[1000];
  24.  
  25. scanf("%d", &n);
  26.  
  27. for(i=0;i<n;i++)
  28. scanf("%d", &a[i]);
  29.  
  30. scanf("%d", &position);
  31. position--;
  32.  
  33. insert(n,a,position);
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment