Created
December 18, 2013 18:30
-
-
Save morganwilde/8027333 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define NROWS 10 | |
#define NCOLS 7 | |
float col_ave(int x[NROWS][NCOLS], int col) { | |
float average; | |
int i, total = 0; | |
for (i = 0; i < NROWS; i++) { | |
total += x[i][col]; | |
} | |
average = total / (float)NROWS; | |
return average; | |
} | |
int main() { | |
// Collect data | |
FILE *data = fopen("power1.dat", "r"); | |
int mo, tu, we, th, fr, sa, su; | |
int temperature[NROWS][NCOLS]; | |
char *dataFormat = "%d %d %d %d %d %d %d"; | |
int i = 0; | |
while (fscanf(data, dataFormat, &mo, &tu, &we, &th, &fr, &sa, &su) != -1) { | |
temperature[i][0] = mo; | |
temperature[i][1] = tu; | |
temperature[i][2] = we; | |
temperature[i][3] = th; | |
temperature[i][4] = fr; | |
temperature[i][5] = sa; | |
temperature[i][6] = su; | |
i++; | |
//printf(dataFormat, mo, tu, we, th, fr, sa, su); | |
//printf("\n"); | |
} | |
fclose(data); | |
data = NULL; | |
// Interpret the data | |
char *days[] = { | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Friday", | |
"Saturday", | |
"Sunday" | |
}; | |
printf("Average energy use on:\n"); | |
for (i = 0; i < NCOLS; i++) { | |
printf("%9s is %.2f MW\n", days[i], col_ave(temperature, i)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment