//ic210 sec4002 //hw 20 //recursive handshake #include using namespace std; int handshakes(int); int main() { int numPeople; //ask for number of people in room cout << "Enter number of people "; cin >> numPeople; //output number handshakes cout << "There will be " << handshakes(numPeople) << " handshakes \n"; return 0; } //recursive function to compute number of handshakes int handshakes(int n) { //base case (simplest input) if (n == 1) { return 0; } //recursive case //assume we know the answer for n-1 //(that is handshakes(n-1)) //extra person comes - shakes hand //with everybody else (n-1 shakes) //total is (n-1) + handshake(n-1) return n-1 + handshakes(n-1); }