current position:Home>How to optimize this program, about the C language to find the correlation coefficient

How to optimize this program, about the C language to find the correlation coefficient

2022-09-23 07:22:23CSDN Q&A

Need to use c language to solve the correlation coefficient
The data are all 0,1
I have 58, I am lazy so I wrote it directly
But my result will appear #INDOO
GoUnderstand it, maybe the denominator may be 0 because my data is 0,1?
[The code is as follows]

#include #include double Corrcoef(double A[],double B[], int Length) ;int main(void){ double a[58],b[58]; int i=0; int Length=58; double sumA, sumB, aveA, aveB; double A=0,B=0,C=0; double result=0; while(i<58){ printf("PleaseEnter the value of the first variable (%d): ",i); scanf("%f",&a[i]); printf("Please enter the value of the second variable (%d):",i); scanf("%f",&b[i]); i++; }//input data sumA=0; sumB=0; i=0; while(i<58){ sumA=a[i]; sumB=b[i]; i++; }//Sum aveA=sumA/(double)Length; aveB=sumB/(double)Length;//Average while(i<58){ A +=(a[i]-aveA)*(b[i]-aveB); B +=pow((a[i]-aveA),2); C +=pow((b[i]-aveB),2); } result=(R1/sqrt(R2*R3)); printf("The correlation coefficient is: %f",result); return 0;}

copyright notice
author[CSDN Q&A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/266/202209161513012926.html

Random recommended