help
i need to create a prgramme that does ..
·
Demonstrates
a ‘for’ loop that produces the
output: 3, 5, 9, 17, 33, 65. (Hint: the loop variable value is first doubled,
then reduced by 1)
Demonstrates a ‘do’
– ‘while’ loop that does exactly the same, just the other way round (Hint:
first add 1 to the loop variable, then divide by 2). However, the 17 must not
be printed out, i.e. the output is: 65, 33, 9, 5, 3
//series.cpp
//##
#include <iostream>
using std::cout;
using std::endl;
int main(){
for(int i=3;i<=66;i*=2){
//if i is equal to 3 just print i; else print i-1
cout<<(i==3?i:i-1)<<' ';
if(i!=3)--i; //if i is not equal to 3 i-1 (decreases i by 1);
}//end for
cout<<endl;
return 0; //indicates success
}//end of main