Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main(void)
- {
- int i, t; // t holds operation results then stores into i
- int total = 0;
- FILE *fp = fopen("day1.txt","r");
- while (fscanf(fp, "%d", &i) == 1) // fscanf goes through file until EOF, and assign read value to variable &i
- {
- while (((i / 3) - 2) >= 0)
- {
- t = ((i / 3) - 2);
- i = t;
- total += i;
- }
- }
- printf("The total is %d\n", total);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement