Advertisement
Sabab

Array Deletion

Feb 4th, 2024
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include<stdio.h>
  2. int main(){
  3.  
  4. int a[100],n,loc,element,i;
  5. printf("Enter the number of ELement: ");
  6. scanf("%d",&n);
  7. printf("Enter the ELements of Array: ");
  8.  
  9. for(i=0;i<n;i++){
  10. scanf("%d",&a[i]);
  11.  
  12. }
  13. printf("a[%d]: ",n);
  14.  
  15. for(i=0;i<n;i++){
  16. printf("%d ",a[i]);
  17.  
  18. }
  19.  
  20. printf("\nEnter the location you want to delete: ");
  21. scanf("%d", &loc);
  22.  
  23. for(i=loc;i<n;i++){
  24.  
  25. a[i]=a[i+1];
  26.  
  27. }
  28. n=n-1;
  29.  
  30. printf("New array, a[%d]: ",n);
  31.  
  32. for(i=0;i<n;i++){
  33. printf("%d ",a[i]);
  34.  
  35. }
  36.  
  37.  
  38. return 0;
  39. }
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement