计算机软件技术基础(VC) 课程设计任务书题目:一元一次回归方程, 急用,谢了
发布网友
发布时间:2023-03-16 13:27
我来回答
共1个回答
热心网友
时间:2023-10-30 06:37
河工大的吧??嘿嘿..我也是托人帮你们写的~~~
#include <stdio.h>
#include <math.h>
#include <string.h>
float mean(float *a, int n);
void deviation(float *a, float mean, int n, float *d, float *S);
int main()
{
float a[20], b[20], dx[20], dy[20];
float sy = 0, sx = 0, mean_x = 0, mean_y = 0, sum_xy = 0;
float corr_coff = 0, reg_coff_xy = 0, reg_coff_yx = 0;
char type_coff[7];
int n = 0, i = 0;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("Enter the values of x and y:\n");
for (i = 0; i < n; i++)
scanf("%f%f", &a[i], &b[i]);
mean_x = mean(a, n);
mean_y = mean(b, n);
deviation(a, mean_x, n, dx, &sx);
deviation(b, mean_y, n, dy, &sy);
for (i = 0; i < n; i++)
sum_xy = sum_xy + dx[i] * dy[i];
corr_coff = sum_xy / (n * sx * sy);
printf("Enter the type of regression coefficient as 'x on y' or 'y on x': ");
fgets(type_coff, 7, stdin);
if (strcmp(type_coff, "x on y") == 1) {
reg_coff_xy = corr_coff * (sx / sy);
printf("\nThe value of linear regression coefficient is %f",
reg_coff_xy);
} else if (strcmp(type_coff, "y on x") == 1) {
reg_coff_yx = corr_coff * (sy / sx);
printf("\nThe value of linear regression coefficient is %f",
reg_coff_yx);
} else
printf("\nEnter the correct type of regression coefficient.");