关于循环
为什么 循环就没有转过程序代码:
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> double rand_u(double Lower, double Upper); double pci(double mean, double variance, int n_samples); int main() { srand((unsigned)time(NULL)); double mean=0.0,variance,sum=0.0,sum_square_data=0.0,data; int n_samples=1; mean = sum/n_samples; variance = sum_square_data/(n_samples)-mean*mean; while (pci(mean,variance,n_samples)>=5) { data = rand_u(0.0,1.0); sum += data; sum_square_data += data*data; n_samples++; } printf("samples number =%d\n",n_samples); printf("sample mean = %lf\n",mean); printf("sample variance = %lf\n",variance ); printf("percentage confidence interval =%lf \n", pci( mean,variance,n_samples)); return 0; } /////////////////////////////////////////////////////////////////////////// double rand_u(double Lower, double Upper) // 随机0-1 { double r=Lower+(rand()/(double)(RAND_MAX+1)*(Upper-Lower)); return r; } double pci(double mean, double variance, int n_samples) { double s=sqrt(variance); double percentage_confidence_interval = ((1.96*s)/sqrt(n_samples))*200; return percentage_confidence_interval; }