crystal ball c 2b 2b

Solutions on MaxInterview for crystal ball c 2b 2b by the best coders in the world

showing results for - "crystal ball c 2b 2b"
Paulina
06 Jan 2018
1#include<iostream> 
2inline int f(int exp, int balls);
3
4int f(int exp, int balls)
5{   
6    if(exp == 0 || balls == 0)
7        return 0 ;
8
9    return f(exp-1, balls)+ f(exp-1,balls-1)+1 ; 
10}
11int main()
12{
13    int experince{0};
14    int balls {0};
15    int floors {0};
16    std::cout<<"Please enter the number of floors: ";
17    std::cin>>floors;
18    std::cout <<"\nPlease enter the number of balls: ";
19    std::cin>>balls;
20
21    while(true)
22    {
23        ++experince;
24        if(f(experince,balls) >= floors)
25            break;
26    }
27
28    std::cout<<"\nNumber experince required "<<experince<<std::endl;
29    return 0 ;
30}