fork download
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int a[6];
  6. int i,k;
  7. int element_choice;
  8. int element;
  9. //printf("enter array elements:");
  10. for(i=0;i<5;i++)
  11. scanf("%d",&a[i]);
  12. //printf("Enter choice\n1.In the beginning of array\n2.At the end of array\n3.At any location of user choice");
  13. //scanf("%d",&choice);
  14. printf("enter the element:");
  15. scanf("%d",&element);
  16. //printf("enter the element after which the number has to be inserted:");
  17. scanf("%d",&element_choice);
  18. for(i=0;i<5;i++)
  19. {
  20. if(a[i]==element_choice)//finding the element
  21. break;
  22. }
  23. for(k=5;k>(i+1);k--){
  24. a[k]=a[k -1];//shifting the element
  25.  
  26. }
  27. a[i+1]=element;
  28.  
  29.  
  30. printf("\n");
  31. for(i=0;i<6;i++)//display the result
  32. printf("%d \t",a[i]);
  33. return 0;
  34. }
Success #stdin #stdout 0s 2296KB
stdin
10
20
30
40
50

90

30

stdout
enter the element:
10 	20 	30 	90 	40 	50