#include<iostream> #include<cmath> #include<iomanip> using namespace std; int main() { int t; cin>>t; while(t--) { int set_size,i; cin>>set_size; int arr[set_size]; for(i=0;i<set_size;i++) { cin>>arr[i]; } unsigned int pow_set_size = pow(2, set_size); int counter, j; float sum_avg=0; cout<<fixed<<setprecision(6); /*Run from counter 000..0 to 111..1*/ for(counter = 0; counter < pow_set_size; counter++) { float avg,sum=0;int no=0; for(j = 0; j < set_size; j++) { /* Check if jth bit in the counter is set If set then pront jth element from set */ if(counter & (1<<j)) { // cout<<arr[j]; sum+=arr[j]; no++; // int no=0,sum=0,digit; // float avg; // while(arr[j]!=0) // { // digit=arr[j]%10; // sum=+digit; // arr[j]/=10; // no++; // // } // avg=sum/no; // // // overall_sum+=avg; // cout<<"overall_sum="<<overall_sum<<endl; } } if(sum!=0) {avg=sum/no; cout<<"avg= "<<avg; sum_avg+=avg; } cout<<endl; } // cout<<fixed<<setprecision(6); cout<<sum_avg<<endl; } return 0; } //1 //3 //2 3 5 //Its Correct output is: //23.333333 //And Your Output is: //23.333334
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)