How can i count the result?

Discussion in 'C' started by marchan, Jan 7, 2016.

  1. marchan

    marchan New Member

    Joined:
    Jan 7, 2016
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hi guys, this the code i found in the net but i did a little changes, my question is how can i count the result at the IF part?
    Code:
    #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;
        float sum=0,mean,deviation=0,standard_deviation;
    
    
       
        if (index == r){
    
    
            for (j=0; j<r; j++)
            {
               sum=sum+data[j];
                deviation=deviation+pow((MEAN-data[j]),2);
            }
            printf("\n");
           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);
         
            else printf("%15d",b); 
      
           return;}
    //}
    
     //fprintf(fin,"\n");
    
           // int c= f;
    
    
       
       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,12,16};
        int r = 4,i,countt=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;
    }
     
  2. marchan

    marchan New Member

    Joined:
    Jan 7, 2016
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    is there anybody who wants to help me?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice