1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <stdio.h>
main()
{
double sum; /*Sum of all numbers*/
double average; /*Average of all numbers*/
int first, second, third, fourth, fifth;
int line = 1;
FILE *inp, /*input file*/
*outp; /*output file*/
/*Open Files*/
inp = fopen("scores.dat", "r");
outp = fopen("outp.out", "w");
printf(outp,"Assignment 7\n");
printf(outp,"Rodolfo Esparza\n");
printf(outp,"K00326334\n\n");
fprintf(outp, " Score1 Score2 Score3 Score4 Score5\t Sum\t Average\n");
fprintf(outp, " ---------\t ---------\t ---------\t ---------\t ---------\t ---------\t ---------\n");
printf("Assignment 7\n");
printf("Rodolfo Esparza\n");
printf("K00326334\n\n");
printf("\tScore1\tScore2\tScore3\tScore4\tScore5\t Sum\tAverage\n");
printf("\t------\t------\t------\t------\t------\t------\t-------\n");
line = 1;
while (line <= 10)
{
fscanf (inp, "%d %d %d %d %d", &first, &second, &third, &fourth, &fifth);
sum = first + second + third + fourth + fifth; //Formula for sum
average = (first + second + third + fourth + fifth)/5; //Formula for average
printf ("\t %d\t %d\t %d\t %d\t %d\t %2.0lf\t %.2lf\n\n", first, second, third, fourth, fifth, sum, average);
fprintf (outp, "\t %d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%2.0lf\t\t%.2lf\n\n", first, second, third,fourth, fifth, sum, average);
line++;
}
fprintf(outp, " ---------\t ---------\t ---------\t ---------\t ---------\t ---------\t ---------\n");
printf("\t------\t------\t------\t------\t------\t------\t ------\n");
/*close Files*/
fclose(inp);
fclose(outp);
system ("pause");
}
|