Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

? Write a C program to take numbers from an input file (input dat), calculate th

ID: 3699431 • Letter: #

Question

? Write a C program to take numbers from an input file (input dat), calculate the sum and average ofthe numbere for each row, and display them in a form of table like the figure below both on screen unharet ieadent Sun Average res any kny to continue- Use these numbers in the input file. (input dat is attached) 0.043200 -0.003471 0.000000 0.100233 0.040326 -0.004851 0.000737 0.022249 0.018204 -0.004246 0.001530 0.161792 0.022249 0.008891 0.004870 0.199106 0.074892 0.044237 0.032171 0.341021 0.129600 0.100233 0.0S9016 0.221134 0.174747 0.160100 0.161792 0.00347S 0.200242 0.199106 0.214417 0.012351 0.174747 0.160100 0.161792 0.032452

Explanation / Answer

Both the source code and input data file are suppose to stored in current folder.

#include <stdio.h>
#include <string.h>

int main()
{
    FILE* fp;
   double A, total;
   int i,counter=0;

if ((fp = fopen("input.dat", "r")) == NULL)
{ /* Open source file. */
    perror("fopen source-file");
    return 1;
}
    printf("N1 N2 N3 N4 SUM AVERAGE ");
while(!feof(fp))
{  
    fscanf(fp,"%lf",&A);
    printf("%lf ",A);    
   counter++;
   total=total+A;
   if(counter%4==0)
   {
   printf("%lf ",total);
   printf("%lf",total/4);
   printf(" ");
   total=0;
   }
}

fclose(fp);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote