Advertisement
Sabab

Array Insert

Feb 4th, 2024
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 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 element you want to insert: ");
  21. scanf("%d", &element);
  22.  
  23. printf("Enter the location in which you want to insert: ");
  24. scanf("%d", &loc);
  25.  
  26. for(i=n-1;i>=loc;i--){
  27. a[i+1]=a[i];
  28.  
  29. }
  30. a[loc]=element;
  31. n=n+1;
  32.  
  33. printf("New Array,a[%d]: ",n);
  34. for(i=0;i<n;i++){
  35. printf("%d ",a[i]);
  36.  
  37. }
  38.  
  39.  
  40. return 0;
  41. }
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement