Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5. int main( )
  6. {
  7.   FILE *fptr;
  8.   int i;
  9.     float x;
  10.  
  11.   fptr = fopen("FileIO_4.out","w");
  12.  
  13.   if(fptr != NULL){
  14.     for(i=0; i<5; i++)
  15.       fprintf(fptr,"%g\n", exp((float)i));
  16.  
  17.     fclose(fptr);
  18.   }
  19.   else
  20.     printf("Unable to open file.\n");
  21.  
  22.   fptr = fopen("FileIO_4.out","r");
  23.  
  24.   if(fptr != NULL){
  25.     for(i=0; i<5; i++){
  26.       fscanf(fptr,"%f", &x);
  27.       printf("Read: %g\n", x);
  28.     }
  29.  
  30.     fclose(fptr);
  31.   }
  32.   else
  33.     printf("Unable to open file.\n");
  34.  
  35.   return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement