Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void)
  5. {
  6.  
  7.     int i, t;         // t holds operation results then stores into i
  8.     int total = 0;
  9.  
  10.  
  11.     FILE *fp = fopen("day1.txt","r");
  12.  
  13.     while (fscanf(fp, "%d", &i) == 1) // fscanf goes through file until EOF, and assign read value to variable &i
  14.     {
  15.         while (((i / 3) - 2) >= 0)
  16.         {
  17.             t = ((i / 3) - 2);
  18.             i = t;
  19.             total += i;
  20.         }
  21.     }
  22.  
  23.  
  24.     printf("The total is %d\n", total);
  25.     fclose(fp);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement