两组数据的样本量必然是一样的,所以只需要输入一次样本量:
#include <stdio.h>
#include <math.h>
double compute_d(double SE1, double SE2, double mean1, double mean2, int num)
{
double S_within = 0.0, d = 0.0, r = 0.0;
S_within = sqrt((SE1*SE1*(num - 1) + SE2 * SE2*(num - 1)) / (num + num - 2));
d = fabs((mean1 - mean2) / S_within);
r = d / sqrt((d*d + 4));
return r;
}
int main()
{
double compute_d(double SE1, double SE2, double mean1, double mean2, int num);
double inp[5], r=0;
int flag;
printf("请输入第一组标准差,第二组标准差,第一组均值,第二组均值,样本量,以空格间隔\n");
for (int i = 0; i < 5; i++)
{
scanf("%lf", &inp[i]);
}
r = compute_d(inp[0], inp[1], inp[2], inp[3], (int)inp[4]);
printf("计算出r系数为:%lf", r);
scanf("%d", &flag);
return 0;
}