How can i rewrite this using a do/while loop in C++ ?
int ctr;
cin%26gt;%26gt;ctr;
while (ctr %26lt;=20)
{
cout%26lt;%26lt;ctr;
ctr++;
}
How can i rewrite this using a do/while loop in C++ ?
int ctr;
cin%26gt;%26gt;ctr;
do
{
if(ctr%26gt;20)
break;
cout%26lt;%26lt;ctr++;
}while(1);
Above method is more fool-proof.. Another simpler way is..
int ctr;
cin%26gt;%26gt;ctr;
do
{
cout%26lt;%26lt;ctr++;
}while(ctr %26lt;= 20);
Problem in this method is, if you get ctr=21(say) in cin, then 21 will be printed.. In the first code, this is avoided.
sweet pea
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment