The Handshake Problem - Recurrence Function in C - Computer Algorithms, Guides, Projects, Research for Algorithms and Programming
hishamnajam
hishamnajam

The Handshake Problem - Recurrence Function in C - Computer Algorithms, Guides, Projects, Research for Algorithms and Programming

1 page
6Number of download
1000+Number of visits
Description
The Handshake problem's implementation as a recursive function in C language.
20 points
Download points needed to download
this document
Download the document
Preview1 page / 1

The Handshake Problem

At a party with n people, everyone shakes hands once with everybody else. Let H(n) be the total number of handshakes among the n guests. Write a recurrence for H(n).

The Recursive Code for the Handshake Problem

#include <stdio.h>

int handshake(int n);

int main() {

printf("%d \n", handshake (25));

return 0;

}

handshake(n) {

if (n == 0)

return 0;

else

return ((n-1) + handshake(n-1));

}

1

no comments were posted