Advertisement
xulfni

PIK 3/30/2020

Mar 30th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int *p, i, n, a;
  7.  
  8.     printf("Enter the size of the array: \n\n");
  9.     scanf("%d", &a);
  10.     p = (int*)calloc(a, sizeof(int));
  11.  
  12.  
  13.     if(p==NULL)
  14.     {
  15.         printf("Memory allocation failed");
  16.         exit(1);
  17.     }
  18.  
  19.     for(i = 0; i < a; i++)
  20.     {
  21.         printf("Enter element at index %d: ", i);
  22.         scanf("%d", p+i);
  23.     }
  24.     int j;
  25.     printf("IncreasinG the size of the array by elements ...\n " );
  26.     scanf("%d", &j);
  27.  
  28.     p = (int*)realloc(p, j * sizeof(int));
  29.  
  30.     if(p==NULL)
  31.     {
  32.         printf("Memory allocation failed");
  33.         exit(1);
  34.     }
  35.  
  36.     printf("\nEnter %d more integers\n\n",j);
  37.  
  38.     for(i = a; i < (j+a); i++)
  39.     {
  40.         printf("Enter element at index %d: ", i);
  41.         scanf("%d", p+i);
  42.     }
  43.  
  44.     printf("\nFinal array: \n\n");
  45.  
  46.     for(i = 0; i < (j+a); i++)
  47.     {
  48.         printf("%d ", *(p+i) );
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement