Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main()
  6. {
  7.     float* ptr;
  8.     int size, i;
  9.    
  10.     printf("Please enter number of floats to be read: ");
  11.     scanf("%d", &size);
  12.    
  13.     ptr = (float*)malloc(size * sizeof(int));
  14.    
  15.     if(ptr != NULL)
  16.     {
  17.         for(i=0; i<size; i++){
  18.             printf("Enter number %d of %d: ", i + 1, size);
  19.             scanf("%f", &ptr[i]);
  20.         }
  21.    
  22.         for(i=0; i<size; i++)
  23.             printf("ptr[%d] = %g\n", i, ptr[i]);
  24.    
  25.         free(ptr);
  26.     }
  27.     else
  28.         printf("FAILURE: Unable to allocate storage.\n");
  29.    
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement