Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created March 29, 2010 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtinth/347592 to your computer and use it in GitHub Desktop.
Save dtinth/347592 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main() {
int num, i, j, current, *data;
FILE* fp = fopen("input.txt", "r");
num = 0;
while (fscanf(fp, "%d", &current) == 1) {
num ++;
}
data = (int*)malloc(num * sizeof(int));
fseek (fp, 0, SEEK_SET);
for (i = 0; i < num; i ++) {
fscanf (fp, "%d", &data[i]);
}
fclose (fp);
fp = fopen("output.txt", "w");
fprintf(fp,
" Xi MA(1) MA(2) MA(3) MA(4) MA(5)\n"
"-------- ----- ----- ----- ----- -----\n");
for (i = 0; i < num; i ++) {
fprintf (fp, "%8d ", data[i]);
for (j = 1; j <= 5; j ++) {
if (i + j < num) {
fprintf (fp, "%5d ", data[i + j] > data[i] ? 1 : 0);
} else {
fprintf (fp, " -- ");
}
}
fprintf (fp, "\n", data[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment