?? 3iv.cpp
字號(hào):
// Combcalc.cpp Combinations calculations program
// Prompts the user for a group and committee size and then
// calculates the number of different committees that can be formed.
#include <iostream.h>
// Factorial() Returns the factorial of the argument n.
// IN: n is a positive integer
float Factorial (float n)
{ float product = 1.0;
while (n > 1.0)
{ product = product * n;
n = n - 1.0;
}
return (product);
}
// Combi() Returns the number of different of committees
// that could be formed from group
// IN: group is a whole-number value greater than committee
// committee is a positive whole-number value.
float Combi (float group, float committee)
{ float combinations;
combinations = Factorial (group) /
(Factorial (group - committee) * Factorial (committee));
return (combinations);
}
void main()
{ float group_size, committee_size, combinations;
float done = 1.0;
while (done > 0.0)
{ cout << "enter the size of the group and committee: ";
cin >> group_size >> committee_size;
if (group_size > committee_size)
{ combinations = Combi (group_size, committee_size);
cout << "for " << group_size << " people and " <<
committee_size << " sized committees, the ";
cout << "number of committees is " <<
combinations << endl;
}
else
cout << " ** illegal values; group must be larger" << endl;
cout << "Do you wish another calculation? ";
cout << " enter 1.0 for yes, 0.0 for no: ";
cin >> done;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -