Question: 1. ( Recursion ) There are n people in a room, where n is an integer greater than or equal to 2. Each person shakes
1. (Recursion) There are n people in a room, where n is an integer greater than or equal to 2. Each person shakes hands once with every other person. What is the total number of handshakes in the room? Write a recursive function to solve this problem, with the following header:
int handshake (int n)
where handshake(n) returns the total number of handshakes for n people in the room. To get you started, if there are only two people in the room, then handshake(2) = 1.
2. (Assigning grades) Write a program that reads 10 students scores, gets the best score, and then assigns grades based on the following scheme:
Grade is A if scores is >= best 10;
Grade is B if scores is >= best 20;
Grade is C if scores is >= best 30;
Grade is D if scores is >= best 40;
Grade is F otherwise.
The program prompts the user to enter all of the 10 scores and concludes by displaying the grades. Here is a sample run:
Enter 10 scores: 85 55 70 58 92 66 78 82 60 75
Student 0 score is 85 and grade is A
Student 1 score is 55 and grade is D
Student 2 score is 70 and grade is C
Student 3 score is 58 and grade is D
Student 4 score is 92 and grade is A
Student 5 score is 66 and grade is C
Student 6 score is 78 and grade is B
Student 7 score is 82 and grade is A
Student 8 score is 60 and grade is D
Student 9 score is 75 and grade is B
3. (Finding the index of the smallest element) Write a function that returns the index of the smallest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header:
int indexOfSmallestElement(double array[], int size)
Write a test program that prompts the use to enter 10 numbers, invokes this method to return and display the index of the smallest element.
4. (Extra Credit) (Counting occurrence of numbers) Write a program that reads 10 integers between 0 and 99 and counts the occurrences of each. Here is a sample run of the program:
Enter 10 integers between 0 and 99: 2 5 6 5 4 3 23 43 2 56
2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time
56 occurs 1 time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
