Use C programming. Commenting code is encouraged. 4. Students\' Queue There are
ID: 3600000 • Letter: U
Question
Use C programming. Commenting code is encouraged.
4. Students' Queue There are many students in School of Engineering and Applied Shits (SEAS). One day, the dean went crazy all of a sudden and wanted all the students to line up. He was so creepy that he even prohibited girls from standing alone, i.e. if there are girls in the queue, they have to stand side by side. So the case where n = 4 (n is the number of students) can be: FFFF, FFFM, MFFF, FFMM,MFFM, MMFF, MMMM Here F stands for a girl and M stands for a boy. The total number of queues that satisfied the dean's need is 7. Can you make a program to find out the total number of possible queues with n students? Hints Methodology of recursion - thinking backwards: How can you add one more student to the end of the line? Sample Input Sample Output Other Requirements Write a recursive function to solve the problem.Explanation / Answer
Here is the program : --------------------------->>>>>>>>>>>>>>>>>>>>>>
/*this program is to count the no of queue as your requirement
//including library*/
#include<stdio.h>
/*defining the recursive function to calculate no. of queue*/
int countQueue(int girls,int boys,const int MAX){
int temp;
/*this will check for the base case*/
if(girls == MAX && boys >= 0){
return 1;
}
/*this line will call the function recursively*/
temp = countQueue(++girls,--boys,MAX);
/*this will return the count of queue*/
return (boys+temp+2);
}
/*starting main function*/
int main(){
/*declaring variable to take the no. of student from user*/
int noOfStudent;
/*declaring variable for no. of queue*/
int queue;
/*prompting the user to give the no. of student*/
printf(" Enter the no. of student ... ");
/*storing the value in noOfStudent*/
scanf("%d",&noOfStudent);
/*calculating the no. of queue by calling the countQueue() recursively*/
queue = 1 + countQueue(2,noOfStudent - 2,noOfStudent);
/*printing the value of no. of queue*/
printf(" %d",queue);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.