Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main(void)
- {
- int fpArray[100]; // holds day1.txt elements
- int i, new_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
- {
- printf("Module mass: %d\n", i);
- while (i >= 0) // holds true while i (which holds the file contents) hits 0 or a negative number
- {
- new_i = ((i / 3) - 2); // perform the calculations and store in new int variable
- printf("\tReducing mass from %d to %d\n", i, new_i);
- i = new_i; // set i to the values inside new_i
- if (i > 0) // if i is still greater than 0
- {
- for (int x = 0; x < 100; x++)
- {
- printf("\tx = %d\n", x); // not exactly sure what this is doing
- new_i = ((i / 3) - 2); // this will be performed up to 100 times as long as i > 0
- printf("\t\tReducing mass from %d to %d\n", i, new_i);
- i = new_i; // same as above
- printf("\t\tTotal so far is %d, adding %d\n", total, i);
- total += i; // maintain total
- }
- }
- }
- }
- printf("%d\n", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement