Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/AminproPastebin
- // Would like to thank Raymond Choo for helping :)
- #include <stdio.h>
- int ways=0;
- int totaltrns=0;
- void queue(int length,int turns){
- turns++;
- if (length>0){
- queue(length-1,turns);
- if (length>1){
- queue(length-2,turns);
- }
- }
- else{
- ways++;
- totaltrns+=turns;
- }
- }
- int main()
- {
- while(1){
- int length;
- float average;
- ways=0;
- totaltrns=0;
- printf("Queue length: ");
- scanf("%d", &length);
- queue(length,-1);
- average=(float)totaltrns/(float)ways;
- printf("The average turns are %.1f\n", average);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement