Maximum Number Of Handshakes | C Program

Maximum number of handshakes in C

Here, in this section we will discuss the program for maximum number of handshakes in C. The user is asked to take a number as integer n and find out the possible number of handshakes. For example, if there are n number of people in a meeting and find the possible number of handshakes made by the person who entered the room after all were settled.

For the number of handshakes to be maximum, every person should shakehand with every other person in the room i.e all persons present should shake hands. For the first person, there would be N-1 people to shake hands. For second person there would N-1 people available but as he had already shaken hands with the first person,  there would be N-2 people to shake hands and so on.

Therefore the total number of handshake = (N-1 + N-2 +….+ 1 + 0)=((N-1)*N)/2.

Maximum number of handshakes in C

Working:-

Step 1: Start

Step 2: The user is asked to insert an integer value n, representing the number of people

Step 3: Find nC2, and calculate as n * (n – 1) / 2.

Step 4: Print the outcome derived from the above program

Step 5: Stop

Maximum number of handshakes
Competitive Coding Techniques

Program to calculate the maximum number of handshakes:

// C program to find the maximum number of handshakesM
#include <stdio.h> 
int main()
{
//fill the code
int num;
scanf("%d",&num);
int total = num * (num-1) / 2; // Combination nC2
printf("%d",total);
return 0;
}

Output

15
105