美好的一天!我在計算遞歸時遇到了一個問題,這段代碼已經在網絡中,但我做了一些額外的代碼,我的問題是如何計算程序的IF部分? ,這是代碼:c遞歸計數
#include <stdio.h>
#include <math.h>
int combinationUtil(int arr[], int data[], int start, int end, int index, int r,float MEAN);
int printCombination(int arr[], int n, int r,float MEAN)
{
int data[r];
combinationUtil(arr, data, 0, n-1, 0, r,MEAN);
}
int combinationUtil(int arr[], int data[], int start, int end, int index, int r,float MEAN)
{
int j,i,a=1,b=0,f=0,ch,total=0;
float sum=0,mean,deviation=0,standard_deviation;
if (index == r){
int count=0;
for (j=0; j<r; j++)
{
sum=sum+data[j];
deviation=deviation+pow((MEAN-data[j]),2);
}
mean=sum/r;
standard_deviation=sqrt(deviation/(r-1));
if(MEAN<=(mean+(2.776*standard_deviation))&& MEAN>=(mean-(2.776*standard_deviation))){
printf("%d",a);
count++;}
else printf("%15d",b);
count=count;
return ;}
for (i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil(arr, data, i+1, end, index+1, r,MEAN);
}
}
int main()
{
int arr[] = {2,4,6,8,10,7,8};
int r = 3,i,count=1,total=0;
int n = sizeof(arr)/sizeof(arr[0]);
float sum=0,MEAN;
for(i=0; i<n; i++)
{
sum=sum+arr[i];
}
MEAN=sum/n;
printf("MEAN=%f\n\n\n",MEAN);
printCombination(arr,n,r,MEAN));
return 0;
}
這是輸出:
」代碼已經在網絡中「。咦? – Drop
「來計算程序的IF部分」你如何計算程序的一部分? – Drop
@Drop我猜OP意味着他從互聯網上獲得了代碼。 – user3437460