Advertisement
Foyaj128

Array short

Apr 15th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1.  
  2. int Insertion_lastpositon (int b[],int nn, int vv);
  3.  
  4. void linear_search(int b[],int nn, int vv);
  5.  
  6. int main ()
  7.  
  8. {
  9. int a[100],n,i,c,b=1,v,p;
  10. printf("\n Enter how many values\n");
  11. scanf("%d",&n);
  12. printf("\n Enter Values\n");
  13. for(i=1;i<=n;i++)
  14. scanf("%d",&a[i]);
  15.  
  16. while (b)
  17. {
  18. printf("\n...........menu.......\n");
  19. printf("\n pres 0 for Quit\n");
  20.  
  21. printf("\n pres 2 for insertion at last position\n");
  22.  
  23. printf("\n pres 5 for linear search\n");
  24.  
  25. printf ("\n Enter your choice\n");
  26. scanf("%d", &c);
  27.  
  28. switch(c)
  29. {
  30. case 0:b=0;
  31. break;
  32.  
  33.  
  34.  
  35. case 2: printf ("\n choice = Insertion at last position \n");
  36. printf("Enter new value \n");
  37. scanf ("%d",&v);
  38. n=Insertion_lastpositon(a,n,v);
  39. break;
  40.  
  41.  
  42. case 5: printf("\n choice =linear_search \n");
  43. if(n!=0)
  44. {
  45. printf("\n Enter Value for searching \n");
  46. scanf ("%d",&v);
  47. linear_search (a,n,v);
  48. }
  49. else
  50. printf("\n No Data to search \n");
  51. break;
  52.  
  53.  
  54.  
  55. }
  56. }
  57.  
  58. }
  59.  
  60. int Insertion_lastpositon (int b[],int nn, int vv)
  61. {
  62. b[nn+1]=vv;
  63. printf("\n Inserted Sucessfully \n\n");
  64. return nn+1;
  65. }
  66.  
  67.  
  68.  
  69. void linear_search(int b[],int nn, int vv)
  70. {
  71. int j,c=0;
  72. for(j=1;j<=nn;j++)
  73. {
  74. if (b[j]==vv)
  75. {
  76. printf("\n Found at position =%d \n",j);
  77. c=c+1;
  78. }
  79. }
  80. if (c==0)
  81. printf("\n Not Found \n");
  82. else
  83. printf("Total Found =%d \n",c);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement