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

answer the following question in C 1. The algorithm to generate the trendline of

ID: 3715928 • Letter: A

Question

answer the following question in C

1. The algorithm to generate the trendline of a set of points is:

Generate Trendline

Calculate the slope

Calculate the y_intercept

Trendline is y = slope * x + y_intercept (y = mx + b form)

Calculate the Slope

Set sum_xy to zero

Set sum_x to zero

Set sum y to zero

Set sum x_sq to zero

Set qty to the number of points in the set

For each point

sum_xy += x * y

sum_x += x

sum_y += y

sum_x_sq += x2

Set slope to ((qty * sum_xy) – (sum_x * sum_y ))/ ((qty * sum_x_sq) – (sum_x2))

Calculate the y_intercept

y_intercept = mean of y – slope * mean of x

Mean of a set of numbers

//left to the user to complete

Sum of a set of numbers

//left to the user to complete

Write a program which accepts 20 points from the user and generates the trendline. The 20 points must be stored in an array of structs using the following definition:

typedef struct

{

double x;

double y;

} Point_t;

Follow the process:

A. Restate the problem

B. Clearly identify the inputs and the outputs

C. Create the algorithm to solve the problem (i.e. generate the pseudocode – you may use the above pseudocode as a starting point, though don’t forget the attribution if you do)

D. Test the pseudocode

E. Write the program

F. Test the program with good input values

Explanation / Answer

#include<stdio.h>
#include<conio.h>

typedef struct

{

double x;

double y;

} Point_t;

main()

{

Point_t array[20];

int qty=20;

int sum_xy=0;

int sum_x=0;

int sum y=0;

int sum x_sq=0;

double slope;

double y_intercept;

y = slope * x + y_intercept;

sum_xy += x * y;

sum_x += x;

sum_y += y;

sum_x_sq += x2;

slope= ((qty * sum_xy) – (sum_x * sum_y ))/ ((qty * sum_x_sq) – (sum_x2));

y_intercept = mean_of_y – slope * mean_of_x;

printf("%d",y_intercept);

getch();

}