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

Write a C program that: - Read two sets of data from a file (HWdata.txt) and sto

ID: 3554831 • Letter: W

Question

Write a C program that:

- Read two sets of data from a file (HWdata.txt) and store them as arrays of length 20. The data is presented as x y form (on each line there will be a value for x and a value for y) where is x is an integer and y is a float value. Continue reading the file and allocating the data into these dynamic arrays. The data file will be provided for you separately.
-Find the estimated slope, b^.
- Find the estimated intercept, a^.
- Find the R2 value for the line created using the previously found estimated slope and intercept.
- Output the equation of the

(I knw the read file isnt included(hwdata.txt), but just add the line to open it and I'll check it)

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
fp=fopen("sensor2.txt","r");
int x[20];
float y[20];
int i;
for(i=0;i<20;i++)
{
fscanf(fp,"%d %f",&x[i],&y[i]);
}

int sum=0; //for sigma(x)
float sum1=0; //for sigma(y)
float sum2=0; //for sigma(x*y)
float sum3=0;//for sigma(x^2)
int sum4=0;

for(i=0;i<20;i++)
{
sum=sum+x[i];
sum1=sum1+y[i];
sum2=sum2+x[i]*y[i];
sum3=sum3+x[i]*x[i];

}

sum4=sum*sum;
float b; //slope
float a; //intercept
b=(20*sum2-sum*sum1)/(20*sum3-sum4);
a=(sum1-b*sum)/20;
printf(" slope is %f. ",b);
printf(" intercept is %f. ",a);

}

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