can somebody please edit the code I have provided as my answer, in order to sati
ID: 3862671 • Letter: C
Question
can somebody please edit the code I have provided as my answer, in order to satisfy question b as well? without completing creating a new code - adding onto this one please !!!
C programming is what I am using.
this is the data I am using: (Think of them as in a data table)
x = -7 -5 -1 0 2 5 6
#Include #define MAX 100 #define MAX 100 ORDER 4 int main() { int m, b, x1, y1, x2, y2; print("Enter the value of x 1:"); scan ff', & times 1); print "Enter the value of x 2:"); scan f("%d", &x2;); orient f" Enter the value of y 1:"); &y1;); print f ("Enter the value of y 2:"); scant("%d", &y2;); m = (y2-y1)/(x2-x1); b = y2 - m*x2; print(" The values of m is: %d ", m); print f(value of b is: ", b); return 0;}Explanation / Answer
The Correst C code
#include <stdio.h> // header file containing input output functions cin,cout
#define MAX 100
int main()
{
// variable declerations
float sumX = 0,sumY = 0,sumXY = 0,sumXsq = 0,x[MAX],y[MAX];
float m, b,S = 0.0; // variables for slop and intersect
int n,i;
printf("Enter the number of data n = "); // asking the user to enter the number of data points
scanf("%d",&n); // scanning the number n
// Prompting the user to enter the values of x
for(i = 0;i<n;i++)
{
printf("Enter the value of x%d: ",i+1);
scanf("%f",&x[i]);
}
// Prompting the user to enter the values of y
for(i = 0;i<n;i++)
{
printf("Enter the value of y%d: ",i+1);
scanf("%f",&y[i]);
}
for(i = 0;i<n;i++)// sum of all x
sumX = sumX + x[i]; // computing summation of x
for(i = 0;i<n;i++) // sum of all y
sumY = sumY +y[i];// computing summation of y
for(i = 0;i<n ;i++) // sum of all (xy)
sumXY = sumXY + x[i]*y[i];// computing summation of x*y
for(i = 0;i<n;i++) // sum of all x^2
sumXsq = sumXsq +x[i]*x[i];// computing summation of x^2
m = ((n*sumXY) - (sumX*sumY)) / ((n*sumXsq) - (sumX*sumX)); // Computing slop
b = ((sumY - (m*sumX)) / n); // Computing the inter section
for(i = 0;i<n;i++)
S = S + (y[i]-b-m*x[i])*(y[i]-b-m*x[i]); // determining the overall error
printf(" The value of m is: %f ",m); // printing the results
printf(" The value of b is: %f ",b); // printing the results
printf(" The value of S is: %f ",S); // printing the results
return 0; // main function returns
}
OUTPUT
Enter the number of data n = 7
Enter the value of x1: -7
Enter the value of x2: -5
Enter the value of x3: -1
Enter the value of x4: 0
Enter the value of x5: 2
Enter the value of x6: 5
Enter the value of x7: 6
Enter the value of y1: 15
Enter the value of y2: 12
Enter the value of y3: 5
Enter the value of y4: 2
Enter the value of y5: 0
Enter the value of y6: -5
Enter the value of y7: -9
The value of m is: -1.778571
The value of b is: 2.857143
The value of S is: 3.992859
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.