#include<iostream>usingnamespace std;doubleAverage(double,double);intmain(){
double x, y;
cout <<"Please enter x and y (0 to quit): ";
cin >> x >> y;while(x && y){
cout <<"The harmonic mean of x and y is: "<<Average(x, y)<< endl;
cout <<"Please enter x and y (0 to quit): ";
cin >> x >> y;}return0;}doubleAverage(double x,double y){
return2.0*x*y /(x+y);}
#include<iostream>usingnamespace std;intInput(double[],int);voidShow(double[],int);doubleMean(double[],int);intmain(){
double ar[10];int len =0;
len =Input(ar,10);Show(ar, len);
cout <<"The mean of the scores is: "<<Mean(ar, len);}intInput(double ar[],int n){
int i =0;
cout <<"Enter the score #"<< i+1<<" (q to quit): ";while(i<n && cin >> ar[i]){
i++;if(i == n)break;else cout <<"Enter the score #"<< i+1<<" (q to quit): ";}return i;}voidShow(double ar[],int len){
for(int i=0; i<len; i++)
cout << ar[i]<<" ";
cout << endl;return;}doubleMean(double ar[],int len){
double ans =0;for(int i=0; i<len; i++)
ans += ar[i];return ans/len;}
#include<iostream>usingnamespace std;longdoubleprobability(unsigned numbers1,unsigned numbers2,unsigned picks1,unsigned picks2);intmain(){
unsigned total1, total2, choices1, choices2;
cout <<"Field number\tpicks\tSecond\tpicks"<< endl;while((cin >> total1 >> choices1 >> total2 >> choices2)&& choices1 <= total1 && choices2 <= total2){
cout <<"You have one chance in ";
cout <<probability(total1, total2, choices1, choices2);
cout <<" of winning."<< endl;
cout <<"Next 4 numbers (q to quit): ";}
cout <<"Bye"<< endl;return0;}longdoubleprobability(unsigned numbers1,unsigned numbers2,unsigned picks1,unsigned picks2){
longdouble ans =1.0;longdouble n;unsigned p;for(n = numbers1, p = picks1; p >0; n--, p--)
ans *= n/p;for(n = numbers2, p = picks2; p >0; n--, p--)
ans *= n/p;return ans;}
#include<iostream>usingnamespace std;longlongfactorial(int n);intmain(){
int n;
cout <<"Please enter the number n (q to quit): ";while(cin >> n){
cout << n <<"! = "<<factorial(n)<< endl;
cout <<"Please enter the number n (q to quit): ";}return0;}longlongfactorial(int n){
if(n ==0|| n ==1)return1;return n*factorial(n-1);}
#include<iostream>usingnamespace std;intFill_array(double ar[],int n);voidShow_array(constdouble ar[],int len);voidReverse_array(double ar[],int len);intmain(){
int n;
cout <<"Please enter the maximum number of the array: ";
cin >> n;double*ar =newdouble[n];int len =Fill_array(ar, n);Show_array(ar, len);Reverse_array(ar, len);Show_array(ar, len);Reverse_array(ar, len);//先让数组变为原来的Reverse_array(ar+1, len-2);//妙啊Show_array(ar, len);delete[] ar;return0;}intFill_array(double ar[],int n){
int len =0;
cout <<"Enter number #"<< len+1<<": ";while(len < n && cin >> ar[len]){
len++;if(len < n) cout <<"Enter number #"<< len+1<<": ";}return len;}voidShow_array(constdouble ar[],int len){
for(int i=0; i<len; i++)
cout << ar[i]<<" ";
cout << endl;return;}voidReverse_array(double ar[],int len){
for(int i=0; i<len/2; i++){
int tmp = ar[i];
ar[i]= ar[len-i-1];
ar[len-i-1]= tmp;}return;}