mhdew

Array Delete using Function

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