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

1. create a source file titled lab_fg.c 2. include a comment at the beginning of

ID: 3816542 • Letter: 1

Question

1. create a source file titled lab_fg.c 2. include a comment at the beginning of the program including your name, who your lab instructir is, and the day and date. 3. the program should begin byaskin the data points he wishes to enter, up to a max of 10. use a loop to ensure that the number entered by the user is valid. once the user has chosen the number of inputs, the program should gather the data (double floating point values) from the user, storing them in an appropriately sized 1-D array. on ce the information is stored in array, you can usethe user defined functions for mean, variance and standard deviation to calculate the mean and standard deviation of the vakues in the array, displaying the results. 4. finally, the program should print the data to a data file with a " number of points" file format. Use the filename labFG.txt. 1. create a source file titled lab_fg.c 2. include a comment at the beginning of the program including your name, who your lab instructir is, and the day and date. 3. the program should begin byaskin the data points he wishes to enter, up to a max of 10. use a loop to ensure that the number entered by the user is valid. once the user has chosen the number of inputs, the program should gather the data (double floating point values) from the user, storing them in an appropriately sized 1-D array. on ce the information is stored in array, you can usethe user defined functions for mean, variance and standard deviation to calculate the mean and standard deviation of the vakues in the array, displaying the results. 4. finally, the program should print the data to a data file with a " number of points" file format. Use the filename labFG.txt. 2. include a comment at the beginning of the program including your name, who your lab instructir is, and the day and date. 3. the program should begin byaskin the data points he wishes to enter, up to a max of 10. use a loop to ensure that the number entered by the user is valid. once the user has chosen the number of inputs, the program should gather the data (double floating point values) from the user, storing them in an appropriately sized 1-D array. on ce the information is stored in array, you can usethe user defined functions for mean, variance and standard deviation to calculate the mean and standard deviation of the vakues in the array, displaying the results. 4. finally, the program should print the data to a data file with a " number of points" file format. Use the filename labFG.txt.

Explanation / Answer


/* Save this file by name lab_fg.c*/ // create file titled lab_fg.c
/* <<your name>> <<your lab instructor name>> <<day and date>> */

#include <stdio.h>
#include <math.h>
#define MAXSIZE 10

void main()
{
double data_points[MAXSIZE];
int i, n;
double average, variance, std_deviation, sum = 0, sum1 = 0;

   FILE *fptr;
   fptr = (fopen("C:\labFG.txt", "w")); //creates a file by name labFG.txt
   if(fptr == NULL)
   {
printf("Error!");
exit(1);
   }
   fprintf(fptr,”The values of data points are: ”);
printf("Enter value for data points to be entered ");
scanf("%d", &n);
printf("Enter %d real numbers ", n);

for(i = 0; i < n; i++)
{
scanf("%lf", &data_points[i]); // reads the input data

fprintf(fptr,"%lf ”,data_points[i]); // print the input data into the file
}
/* Compute the sum of all elements */
for (i = 0; i < n; i++)
{
sum = sum + x[i];
}
average = sum / (double)n;

/* Compute variance and standard deviation */
for (i = 0; i < n; i++)
{
sum1 = sum1 + pow((x[i] - average), 2);
}
variance = sum1 / (double)n;
std_deviation = sqrt(variance);
  
fprintf("Average of all elements = %.2lf ", average);
fprintf("variance of all elements = %.2lf ", variance);
fprintf("Standard deviation = %.2lf ", std_deviation);
fclose(fptr);
return 0;
}