Need some help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include <iostream.h>
int main()
{
	int p,t,n;
	cout << "N=";
	cin >> n;
	p=1;
	t=0;
	while(p<n)
	{
		t=t+p;
		p=p*2;
	}
cout << t << endl;
cout << p << endl;
}


a)Write the statement of this code.(I know it's something about odd and even numbers, I can't figure it out)
b)For how many values of N the code outputs t=32 and p=31 (How do I solve problems like this b)?I have no idea)
c)Rewrite the code using do-while (keep the algorithm)

//I know that iostream.h is deprecated but I'm in a hurry, so excuse me.
Last edited on
Do while is different than while loops. While has a min runs of 0 and do/have a min run of 1
For b there are 16 values?Is that right?
Thanks!
Topic archived. No new replies allowed.