Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please complete in a way it can be copied and pasted to codeblocks and PLEASE sh

ID: 3775009 • Letter: P

Question

Please complete in a way it can be copied and pasted to codeblocks and PLEASE show that it runs We have n people in a room, where n is an integer greater than or equal to 1. Each person shakes hands once with every other person. What is the total number, h(n), of handshakes? Write a recursive function to solve this problem. To get you started, if there are only one or two people in the room, then handshake (1) handshake (2) 1 If a third person enters the room, he or she must shake hands with each of the two people already there. This is two handshakes in addition to the number

Explanation / Answer

#include <iostream>

using namespace std;

/*Number_of_Handshake function definition*/
int Number_of_Handshake(int n)
{
/*if there are only one people then return 0 */
if(n==1)
{
return 0;
}
else
{
/*call recursive function Number_of_Handshake*/
return((n-1)+ Number_of_Handshake(n-1));

}

}
int main()
{
/*integer variable number define for number of peoplr*/
int number;

/*print message "Enter the Number of people (N) in a Room (N>=1)"*/
cout << "Enter the Number of people (N) in a Room (N>=1)." << endl;

/*Read number from user*/
cin>>number;

/*call Number_of_Handshake function and and print output*/
cout<<"Total Number of Handshake of ("<<number<<") people is : "<<Number_of_Handshake(number)<<endl;

return 0;
}

---------------------------------------------------------------------------------------

output sample 1:-

Enter the Number of people (N) in a Room (N>=1).
10
Total Number of Handshake of (10) people is : 45

----------------------

output sample 2:-

Enter the Number of people (N) in a Room (N>=1).
2
Total Number of Handshake of (2) people is : 1

-------------------------------------------------

output sample 3:-

Enter the Number of people (N) in a Room (N>=1).
5
Total Number of Handshake of (5) people is : 10

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote