// LKM // hw20.cpp // Computes how many handshakes are needed if // everyone in a room of N people shakes hands // with everyone else.#include #include using namespace std; int handshake(int n); int main() { // Get input int N; cout << "Enter N: " << endl; cin >> N; // Compute and show output cout << "For " << N << " people, " << handshake(N) << " handshakes are needed." << endl; return 0; } // Computes how many handshakes for N people to each // greet each other int handshake(int n) { // base case -- one person means no shakes if (n <= 1) { return 0; } // Recursive step -- shakes needed is number for N-1 people // plus shakes needed if one more person comes in (N-1) return handshake(n-1) + (n-1); }