Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #define __USE_MINGW_ANSI_STDIO 1
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5.  
  6. int main()
  7. {
  8.   FILE *fptr;
  9.     char fname[] = "Array_of_10_long_double.out";
  10.     long double x, ld[10];
  11.   int i;
  12.  
  13.   for(i=0; i<10; i++)
  14.         ld[i] = sqrtl((long double)(i + 1));
  15.  
  16.     printf("long double array size: %d\n", sizeof(ld));
  17.  
  18.   fptr = fopen(fname,"wb");
  19.   if(fptr)
  20.     {
  21.         fwrite(ld, 10, sizeof(long double), fptr);
  22.     fclose(fptr);
  23.   }
  24.   else
  25.     printf("Unable to open file.\n");
  26.  
  27.   fptr = fopen(fname,"rb");
  28.   if(fptr)
  29.     {
  30.     for(i=0; i<10; i++)
  31.         {
  32.       fread(&x, 1, sizeof(long double), fptr);
  33.       printf("%2d) %.21Lf\n", i + 1, x);
  34.     }
  35.     fclose(fptr);
  36.   }
  37.   else
  38.     printf("Unable to open file.\n");
  39.  
  40.   return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement