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

Follow these detailed instructions: First, read this document in its entirety. I

ID: 3711286 • Letter: F

Question

Follow these detailed instructions:

First, read this document in its entirety.

Include the usual (detailed) comment block including program name, author, date, inputs, outputs and description, followed by your preprocessor directives.

An outline (Skeleton-code) of the source code is shown below and you are REQUIRED to follow this outline. Insert appropriate printf statements where needed to get the desired output. Declare and use variables as you require them. The outline has five sections where you are to enter in your code and complete the program.

Part 1: Open two files for input and read the data into two arrays (x and y). Include all appropriate error checks. You may assume that your input files will never exceed 200 floating point numbers and that both x data and y data files will be of equal length, so once you know the length of one file in the pair you can assume that the other file is of the same length.

Part 2: You are required to write the function called sum which accepts an array, and a parameter named size which indicates the size of the array. This function calculates the sum of the elements in the array and returns it to the calling function. Call this function once with the x data and once with the y data and print out the results to the screen from calling function.

Part 3: You are required to write the function call sum_prod which accepts two arrays, and a parameter named size which indicates the size of the arrays. This function calculates the sum of the product of corresponding elements in the two arrays i.e. array1[0]*array2[0]+array1[1]*array2[1]+…array1[N-1]*array2[N-1]. The sum is then returned to the calling function and the result is printed to the screen.

Part 4: You are required to write the function call sum_square which accepts an array, and a parameter named size which indicates the size of the array. This function calculates the sum of the square of each array element i.e. (array1[0])2 + (array1[1])2 + … (array1[N-1])2. Call this function once with the x data and once with the y data and print out the results to the screen from calling function.

EXTRA CREDIT: Part 5: Calculate the correlation coefficient, r, in main()and display the result to the screen.

This is a beginner coding class! Please do not use too complicated stuff and comments help me understand what you are doing. Thank you! IN C PROGRAMMING

Problem: Write a C program to find the following given two data sets, x and y N-1 N-1 N-11,2 Extra credit: Find the correlation coefficient, r, between two data sets, x and y, using the equation below: OUTPUT TABLE Sum of squares Sum of products EXTRA CREDIT:r Filename Sum datax.txt datay.txt

Explanation / Answer

PLEASE REFER BELOW CODE

#include<stdlib.h>
#include<stdio.h>

float sum(float *arrayx, int length_array)
{
int i;
float Sum ;
Sum = 0.0;
for(i = 0; i < length_array; i++)
Sum += arrayx[i];

return Sum;
}

float sum_prod(float *arrayx,float *arrayy,int length_array)
{
int i;
float Sum;
Sum = 0.0;

for(i = 0; i < length_array; i++)
Sum += (arrayx[i] * arrayy[i]);

return Sum;
}
float sum_square(float *arrayx,int length_array)
{
int i;
float Sum;
Sum = 0.0;

for(i = 0; i < length_array; i++)
Sum += (arrayx[i] * arrayx[i]);

return Sum;
}

int main()
{
FILE *fx;
FILE *fy;
float arrayx[200] = {0.0};
float arrayy[200] = {0.0};
int i,length_array;
float sum_array;
fx = fopen("datax.txt","r");
fy = fopen("datay.txt","r");

//chcking file datax.txt present
if(fx == NULL)
{
printf(" datax.txt File is not presnt ");
return 0;
}
else
{
i = 0;
//reading file line by line and store the numbers into array
while(!feof(fx))
{
fscanf(fx, "%f", &arrayx[i]);
i++;
length_array++;
}
fclose(fx);
}
//chcking file datax.txt present
if(fy == NULL)
{
printf(" datay.txt File is not presnt ");
return 0;
}
else
{
i = 0;
//reading file line by line and store the numbers into array
while(!feof(fy))
{
fscanf(fy, "%f", &arrayy[i]);
i++;
}
fclose(fy);
}
sum_array = sum(arrayx,length_array);
printf(" Sum of array of X data = %f ", sum_array);

sum_array = sum(arrayy,length_array);
printf(" Sum of array of Y data = %f ", sum_array);

sum_array = sum_prod(arrayx,arrayy,length_array);
printf(" Sum of product of two arrays = %f ", sum_array);

sum_array = sum_square(arrayx,length_array);
printf(" Sum of the square of each array element of X = %f ", sum_array);

sum_array = sum_square(arrayy,length_array);
printf(" Sum of the square of each array element of Y = %f ", sum_array);

return 0;
}

datax.txt

12.3
11.1
9.5
1.1
2.3

datay.txt

8.3
2.1
3.4
2.2
1.0

PLEASE REFER BELOW OUTPUT


Sum of array of X data = 36.299999

Sum of array of Y data = 17.000000

Sum of product of two arrays = 162.419998

Sum of the square of each array element of X = 371.250031

Sum of the square of each array element of Y = 90.699997

Process returned 0 (0x0) execution time : 0.027 s
Press any key to continue.

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