Rewrite the following for-loop as a pre-test while-loop. (6)
for x = 1 to 10
for y = 10 to x
if y MOD 2 = 0 then
display "*"
else
display "#"
endif
display " " ~newline
#include <iostream>
using namespace std;
int main()
{
int x = 1;
int y = 10;
while (x <= 10)
{
x++;
while (y >= x)
{
y--;
#if y % 2 == 0
{
cout << "*";
}
#else
{
cout << "#";
}
#endif
{
cout << " " << '\n';
}
break;
}
}
return 0;
}
Comments
Leave a comment