fork download
  1. #include<stdio.h>
  2. int arr[100];
  3. int last=0;
  4.  
  5. void insert(int value)
  6. {
  7. arr[last]=value;
  8. last++;
  9. }
  10.  
  11. int search(int value)
  12. {
  13. int i;
  14. for(i=0;i<last;i++)
  15. {
  16. if(arr[i]==value)
  17. return 1;
  18. }
  19.  
  20. return 0;
  21. }
  22.  
  23. void deleteval(int value)
  24. {
  25. int i,pos=-1;
  26. for(i=0;i<last;i++)
  27. {
  28. if(arr[i]==value)
  29. {
  30. pos=i; //finds the position of the value
  31. break;
  32. }
  33. }
  34.  
  35. if(pos>=0)//if value exists
  36. {
  37. for(i=pos+1;i<last;i++) //shifting
  38. {
  39. arr[i-1]=arr[i];
  40. }
  41. last--;
  42. printf("%d value deleted\n",value);
  43. }
  44. else
  45. printf("%d value not found\n",value);
  46. }
  47.  
  48. void printlist()
  49. {
  50. int i;
  51. for(i=0;i<last;i++)
  52. printf("%d\n",arr[i]);
  53. }
  54. int main()
  55. {
  56. int num;
  57.  
  58. //Enter values
  59. while(true)
  60. {
  61. printf("Enter value(-1 to exit): ");
  62. scanf("%d",&num);
  63.  
  64. if(num<0) break;
  65.  
  66. insert(num);
  67. }
  68.  
  69. //Printh the list
  70. printf("\nHere goes the list:\n");
  71. printlist();
  72.  
  73.  
  74. //Search for a value
  75. if(search(10)==1)
  76. printf("yes, the number is in the list");
  77. else
  78. printf("no, the number is not in the list");
  79.  
  80. deleteval(10);
  81. printf("\n Now the list:\n");
  82. printlist();
  83.  
  84. return 0;
  85. }
  86.  
Success #stdin #stdout 0s 2900KB
stdin
10 
20
-1
stdout
Enter value(-1 to exit): Enter value(-1 to exit): Enter value(-1 to exit): 
Here goes the list:
10
20
yes, the number is in the list10 value deleted

 Now the list:
20