You are using a version without Ads of this website. Please, consider donating:

### As I can order several test cases, while receiving data???????

PROBLEM
As I can order several test cases, while receiving data???????

MY PROBLEM
entrance
The entry contains the number you want to represent in binary.

exit
Enter in a line the minimum number of bits required to represent this number.

Examples of input

32
12
1

Output examples

6
4
1

MY BAD SOLUTION
# include <iostream>

using namespace std;

int main ()
{
long long int n, c;
cin >> n;
c = 0;
while (c + +, n> 1)
{
n = n / 2;
}
cout << c;
}
The while statement does not accept a comma-separted list,mean that you cannot do while(,,,,,,) otherwise if you want to check various condition ,you can use some logical operators like && and || exp

`while(condition||condition)`

this another version of your program

 ``123456789101112131415161718`` ``````# include using namespace std; int main () { long long int n, c; cin >> n; c = 1; while (n>1) { n = n / 2; c++; } cout << c << endl; return 0; }``````

His example is still valid.

`while(c++, n>1)`
evaluates to
`while(1) { c++; if(!(n>1)) break; [...] }`

What's wrong with your code @op?
Last edited on
EssGeEich is right. Your code should work.

I compiled your code with some cout statement and verified it be working
 ``12345678910111213`` ``````int main () { int n, c; cout << "Enter the number" << endl; cin >> n; c = 0; while(c++, n> 1){ n = n / 2; } cout << c << endl; return 0; }``````

The output is
 ``` Enter the number 54 6 Press any key to continue . . . ```
Last edited on
Topic archived. No new replies allowed.