Advertisement
Sabbir-bin

Array_Delete

Feb 2nd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1.  #include<stdio.h>
  2. int main()
  3. {
  4.   int a[10], i ,n , newvalue , newindex=-1;
  5.   printf("enter the value of n: ");
  6.   scanf("%d", &n);
  7.   printf( "\nenter %d elements:  " ,n);
  8.   for(i=0; i<n; i++)
  9.   {
  10.     scanf("%d",&a[i]);
  11.  
  12.   }
  13.   printf("\n\nso th elements in the array are: ");
  14.   for(i=0; i<n; i++)
  15.   {
  16.     printf("  %d", a[i]);
  17.  
  18.   }
  19.   printf ("\n\nenter the value that you search: ");
  20.   scanf("%d",&newvalue);
  21.  
  22.   for(i=0; i<n; i++)
  23.  
  24.   {
  25.     if (a[i] == newvalue)
  26.  
  27.     {
  28.       newvalue=i;
  29.       printf("\n\nfound at index no %d ", i);
  30.       break;
  31.     }
  32.   }
  33.  
  34.   if (newindex==-1)
  35.   {
  36.     printf ("\nthe value not found");
  37.   }
  38.  
  39.   else
  40.   {
  41.     for(i=newindex; i<n; i++)
  42.       a[i]=a[i+1];
  43.   }
  44.   printf ("\n\nafter deleting the value: ");
  45.  
  46.   for(i=0; i<n-1; i++)
  47.  
  48.   {
  49.     printf(" %d" , a[i]);
  50.   }
  51.   printf("\n\n");
  52.   return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement