Niloy007

Aurna's Problem 2

Nov 18th, 2020
434
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int arr[50];
  4. int size, item;
  5.  
  6. void arrayPrint() {
  7.     for(int i = 0; i < size; i++) {
  8.         if(i == size - 1) {
  9.             printf("%d\n", arr[i]);
  10.         } else {
  11.             printf("%d,", arr[i]);
  12.         }
  13.     }
  14. }
  15.  
  16.  
  17. void deleteItem() {
  18.     int index;
  19.     for(int i = 0; i < size; i++) {
  20.         if(arr[i] == item) {
  21.             index = i;
  22.         }
  23.     }
  24.  
  25.     for(int i = index; i < size; i++) {
  26.         arr[i] = arr[i + 1];
  27.     }
  28.     size--;
  29. }
  30.  
  31.  
  32. int main() {
  33.     printf("Enter how many elements :\n");
  34.     scanf("%d", &size);
  35.     printf("Enter the elements :\n");
  36.     for(int i = 0; i < size; i++) {
  37.         scanf("%d", &arr[i]);
  38.     }
  39.     printf("Enter element you want to delete :\n");
  40.     scanf("%d", &item);
  41.    
  42.     printf("The array before deletion :\n");
  43.     arrayPrint();
  44.     deleteItem();
  45.     printf("The array after deletion :\n");
  46.     arrayPrint();
  47. }
RAW Paste Data